June 2017
Intermediate to advanced
400 pages
8h 44m
English
The contains() operator will check whether a specific element (based on the hashCode()/equals() implementation) ever emits from an Observable. It will return a Single<Boolean> that will emit true if it is found and false if it is not.
In the following code snippet, we emit the integers 1 through 10000, and we check whether the number 9563 is emitted from it using contains():
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.range(1,10000) .contains(9563) .subscribe(s -> System.out.println("Received: " + s)); }}
The output of the preceding code snippet is as follows:
Received: true
As you can probably guess, the moment the element is found, it will emit true and call onComplete() ...
Read now
Unlock full access