June 2017
Intermediate to advanced
400 pages
8h 44m
English
You can get a specific emission by its index specified by a Long, starting at 0. After that item is found and emitted, onComplete() will be called and the subscription will be disposed of.
If you want to get the fourth emission coming from an Observable, you can do it as shown in the following code snippet:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Zeta", "Eta", "Gamma", "Delta") .elementAt(3) .subscribe(i -> System.out.println("RECEIVED: " + i)); }}
The output of the following code snippet is as follows:
RECEIVED: Eta
You may not have noticed, but elementAt() returns Maybe<T> instead of Observable<T>. This is because it will yield one emission, ...
Read now
Unlock full access