- 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 - Combining Operators
Following are the operators which are used to create a single Observable from multiple Observables.
Sr.No. | Operator & Description |
---|---|
1 |
And/Then/When
Combine item sets using Pattern and Plan intermediaries. |
2 |
CombineLatest
Combine the latest item emitted by each Observable via a specified function and emit resulted item. |
3 |
Join
Combine items emitted by two Observables if emitted during time-frame of second Observable emitted item. |
4 |
Merge
Combines the items emitted of Observables. |
5 |
StartWith
Emit a specified sequence of items before starting to emit the items from the source Observable |
6 |
Switch
Emits the most recent items emitted by Observables. |
7 |
Zip
Combines items of Observables based on function and emits the resulted items. |
Combining Operator Example
Create the following Java program using any editor of your choice in, say, C:> RxJava.
ObservableTester.java
import io.reactivex.Observable; //Using combineLatest operator to combine Observables pubpc class ObservableTester { pubpc static void main(String[] args) { Integer[] numbers = { 1, 2, 3, 4, 5, 6}; String[] letters = {"a", "b", "c", "d", "e", "f", "g"}; final StringBuilder result = new StringBuilder(); Observable<String> observable1 = Observable.fromArray(letters); Observable<Integer> observable2 = Observable.fromArray(numbers); Observable.combineLatest(observable1, observable2, (a,b) -> a + b) .subscribe( letter -> result.append(letter)); System.out.println(result); } }
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 −
g1g2g3g4g5g6Advertisements