February 2020
Intermediate to advanced
412 pages
9h 36m
English
You can get a specific emission by its index specified by the long value, starting at 0. After the item is found and emitted, onComplete() is called and the subscription is disposed of.
For example, 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.rxjava3.core.Observable;public class Ch3_13 { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Zeta", "Eta", "Gamma") .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 yields ...
Read now
Unlock full access