Observables
- RxJava - How Observable works
- RxJava - Creating Observables
- RxJava - Using Flowable
- RxJava - Using Observable
- RxJava - Single Observable
- RxJava - Maybe Observable
- RxJava - Completable Observable
- RxJava - Using CompositeDisposable
Operators
- RxJava - Creating Operators
- RxJava - Transforming Operators
- RxJava - Filtering Operators
- RxJava - Combining Operators
- RxJava - Utility Operators
- RxJava - Conditional Operators
- RxJava - Mathematical Operators
- RxJava - Connectable Operators
Subjects
- RxJava - Subjects
- RxJava - PublishSubject
- RxJava - BehaviorSubject
- RxJava - ReplaySubject
- RxJava - AsyncSubject
- RxJava - UnicastSubject
Schedulers
- RxJava - Schedulers
- RxJava - Trampoline Scheduler
- RxJava - NewThread Scheduler
- RxJava - Computation Scheduler
- RxJava - IO Scheduler
- RxJava - From Scheduler
Miscellaneous
RxJava Useful Resources
RxJava - Mathematical Operators
Following are the operators which operates on entire items emitted by an Observable.
| Sr.No. | Operator & Description |
|---|---|
| 1 |
concat Emits all items from multiple Observable without interleaving. |
| 2 |
count Counts all items and emit the result. |
| 3 |
reduce Apply a function on each item and return the result. |
| 4 |
sum Evaluates sum of all items and emit the result. |
Example - Usage of count operator
ObservableTester.java
package com.tutorialspoint;
import io.reactivex.rxjava3.core.Observable;
//Using count operator to operate on an Observable
public class ObservableTester {
public static void main(String[] args) {
String[] letters = {"a", "b", "c", "d", "e", "f", "g"};
Observable.fromArray(letters)
.count()
.subscribe(System.out::println);
}
}
Output
Compile and Run the code to verify the following output −
7
Example - Usage of reduce operator
ObservableTester.java
package com.tutorialspoint;
import io.reactivex.rxjava3.core.Observable;
//Using reduce operator to get sum of numbers
public class ObservableTester {
public static void main(String[] args) {
Observable.just(1,2,3,4,5,6,7)
.reduce(0, (a,b) -> a + b)
.subscribe(s -> System.out.println("Sum: " + s));
}
}
Output
Compile and Run the code to verify the following output −
28
Advertisements