February 2020
Intermediate to advanced
412 pages
9h 36m
English
A different flavor of toList() operator is toSortedList(). It collects the emitted values into a List object that has the elements sorted in a natural order (based on their Comparable implementation). Then, it pushes that List<T> object with sorted elements into the Observer:
import io.reactivex.rxjava3.core.Observable;public class Ch3_33 { public static void main(String[] args) { Observable.just("Beta", "Gamma", "Alpha") .toSortedList() .subscribe(s -> System.out.println("Received: " + s)); }}
The output of the preceding code snippet is as follows:
Received: [Alpha, Beta, Gamma]
As with the sorted() operator, you can provide a Comparator as an argument to apply a different sorting logic. You can also specify an initial capacity ...
Read now
Unlock full access