- RxJava - Discussion
- RxJava - Useful Resources
- RxJava - Quick Guide
- RxJava - Windowing
- RxJava - Buffering
- RxJava - From Scheduler
- RxJava - IO Scheduler
- RxJava - Computation Scheduler
- RxJava - NewThread Scheduler
- RxJava - Trampoline Scheduler
- RxJava - Schedulers
- RxJava - AsyncSubject
- RxJava - ReplaySubject
- RxJava - BehaviorSubject
- RxJava - PublishSubject
- RxJava - Subjects
- RxJava - Connectable Operators
- RxJava - Mathematical Operators
- RxJava - Conditional Operators
- RxJava - Utility Operators
- RxJava - Combining Operators
- RxJava - Filtering Operators
- RxJava - Transforming Operators
- RxJava - Creating Operators
- RxJava - Using CompositeDisposable
- RxJava - Completable Observable
- RxJava - MayBe Observable
- RxJava - Single Observable
- RxJava - Creating Observables
- RxJava - How Observable works
- RxJava - Environment Setup
- RxJava - Overview
- RxJava - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
RxJava - Conditional Operators
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 pubpc class ObservableTester { pubpc 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 aAdvertisements