June 2017
Intermediate to advanced
400 pages
8h 44m
English
A common collection operator is toList(). For a given Observable<T>, it will collect incoming emissions into a List<T> and then push that entire List<T> as a single emission (through Single<List<T>>). In the following code snippet, we collect string emissions into a List<String>. After the preceding Observable signals onComplete(), that list is pushed forward to the observer to be printed:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon") .toList() .subscribe(s -> System.out.println("Received: " + s)); }}
The output of the preceding code snippet is as follows:
Received: [Alpha, Beta, Gamma, Delta, Epsilon]
By default, toList() ...
Read now
Unlock full access