📅  最后修改于: 2020-11-12 05:29:22             🧑  作者: Mango
以下是对Observables经常有用的运算符。
Sr.No. | Operator & Description |
---|---|
1 |
Delay Register action to handle Observable life-cycle events. |
2 |
Materialize/Dematerialize Represents item emitted and notification sent. |
3 |
ObserveOn Specify the scheduler to be observed. |
4 |
Serialize Force Observable to make serialized calls. |
5 |
Subscribe Operate upon the emissions of items and notifications like 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 lifespan as that of Observable. |
使用您选择的任何编辑器(例如,C:\> RxJava)创建以下Java程序。
import io.reactivex.Observable;
//Using subscribe operator to subscribe to an Observable
public class ObservableTester {
public static void main(String[] args) {
String[] letters = {"a", "b", "c", "d", "e", "f", "g"};
final StringBuilder result = new StringBuilder();
Observable observable = Observable.fromArray(letters);
observable.subscribe( letter -> result.append(letter));
System.out.println(result);
}
}
使用javac编译器编译类,如下所示:
C:\RxJava>javac ObservableTester.java
现在如下运行ObservableTester-
C:\RxJava>java ObservableTester
它应该产生以下输出-
abcdefg