February 2020
Intermediate to advanced
412 pages
9h 36m
English
The single() operator returns a Single that emits the item emitted by this Observable. If the Observable emits more than one item, the single() operator throws an exception. If the Observable emits no item, the Single, produced by the single() operator, emits the item passed to the operator as a parameter. Here is an example:
import io.reactivex.rxjava3.core.Observable;public class Ch3_65 { public static void main(String[] args) { Observable.just("One") .single("Four") .subscribe(i -> System.out.println("Received: " + i)); }}
The output is as follows:
Received: One
Now, let's make sure that nothing gets to the single() operator by filtering out all the items using the following code:
import io.reactivex.rxjava3.core.Observable ...Read now
Unlock full access