February 2020
Intermediate to advanced
412 pages
9h 36m
English
If you have a finite Observable<T> that emits items that are of a primitive type, String type, or objects that implement Comparable<T>, you can use sorted() to sort the emissions. Internally, it collects all the emissions and then re-emits them in the specified order. In the following code snippet, we sort items coming from Observable<Integer> so that they are emitted in their natural order:
import io.reactivex.rxjava3.core.Observable;public class Ch3_17 { public static void main(String[] args) { Observable.just(6, 2, 5, 7, 1, 4, 9, 8, 3) .sorted() .subscribe(System.out::print); }}
The output of the preceding code snippet is as follows (note that, in order to make the output more compact, we use print() in this example, instead of ...
Read now
Unlock full access