February 2020
Intermediate to advanced
412 pages
9h 36m
English
The toList() is probably the most often used among all the collection operators. For a given Observable<T>, it collects incoming items into a List<T> and then pushes that List<T> object as a single value through Single<List<T>.
In the following code snippet, we collect String values into a List<String>. After the preceding Observable signals onComplete(), that list is pushed into the Observer to be printed:
import io.reactivex.rxjava3.core.Observable;public class Ch3_30 { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma") .toList() .subscribe(s -> System.out.println("Received: " + s)); }}
The output of the preceding code snippet is as follows:
Received: [Alpha, Beta, Gamma]
By default, toList()
Read now
Unlock full access