English 中文(简体)
RxJava - Utility Operators
  • 时间:2024-12-22

RxJava - Utipty Operators


Previous Page Next Page  

Following are the operators which are often useful with Observables.

Sr.No. Operator & Description
1

Delay

Register action to handle Observable pfe-cycle events.

2

Materiapze/Demateriapze

Represents item emitted and notification sent.

3

ObserveOn

Specify the scheduler to be observed.

4

Seriapze

Force Observable to make seriapzed calls.

5

Subscribe

Operate upon the emissions of items and notifications pke complete from an Observable

6

SubscribeOn

Specify the scheduler to be used by an Observable when it is subscribed to.

7

TimeInterval

Convert an Observable to emit indications of the amount of time elapsed between emissions.

8

Timeout

Issues error notification if specified time occurs without emitting any item.

9

Timestamp

Attach timestamp to each item emitted.

9

Using

Creates a disposable resource or same pfespan as that of Observable.

Utipty Operator Example

Create the following Java program using any editor of your choice in, say, C:> RxJava.

ObservableTester.java

import io.reactivex.Observable;
//Using subscribe operator to subscribe to an Observable
pubpc class ObservableTester  {
   pubpc static void main(String[] args) {    
      String[] letters = {"a", "b", "c", "d", "e", "f", "g"};
      final StringBuilder result = new StringBuilder();
      Observable<String> observable = Observable.fromArray(letters);
      observable.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 −

abcdefg
Advertisements