following are the operators which evaluates one or multiple observables or items emitted.
sr.no. | operator & description |
---|---|
1 |
all evaluates all items emitted to meet given criteria. |
2 |
amb emits all items from the first observable only given multiple observables. |
3 |
contains checks if an observable emits a particular item or not. |
4 |
defaultifempty emits default item if observable do not emit anything. |
5 |
sequenceequal checks if two observables emit the same sequence of items. |
6 |
skipuntil discards items emitted by first observable until a second observable emits an item. |
7 |
skipwhile discard items emitted by an observable until a given condition becomes false. |
8 |
takeuntil discards items emitted by an observable after a second observable emits an item or terminates. |
9 |
takewhile discard items emitted by an observable after a specified condition becomes false. |
conditional operator example
create the following java program using any editor of your choice in, say, c:\> rxjava.
observabletester.java
import io.reactivex.observable; //using defaultifempty operator to operate on an observable public class observabletester { public static void main(string[] args) { final stringbuilder result = new stringbuilder(); observable.empty() .defaultifempty("no data") .subscribe(s -> result.append(s)); system.out.println(result); string[] letters = {"a", "b", "c", "d", "e", "f", "g"}; final stringbuilder result1 = new stringbuilder(); observable.fromarray(letters) .firstelement() .defaultifempty("no data") .subscribe(s -> result1.append(s)); system.out.println(result1); } }
verify the result
compile the class using javac compiler as follows −
c:\rxjava>javac observabletester.java
now run the observabletester as follows −
c:\rxjava>java observabletester
it should produce the following output −
no data a