官术网_书友最值得收藏!

Observable.range()

To emit a consecutive range of integers, you can use Observable.range(). This will emit each number from a start value and increment each emission until the specified count is reached. These numbers are all passed through the onNext() event, followed by the  onComplete() event:

    import io.reactivex.Observable;

public class Launcher {
public static void main(String[] args) {
Observable.range(1,10)
.subscribe(s -> System.out.println("RECEIVED: " + s));

}
}

The output is as follows:

    RECEIVED: 1
RECEIVED: 2
RECEIVED: 3
RECEIVED: 4
RECEIVED: 5
RECEIVED: 6
RECEIVED: 7
RECEIVED: 8
RECEIVED: 9
RECEIVED: 10

Note closely that the two arguments for Observable.range() are not lower/upper bounds. The first argument is the starting value. The second argument is the total count of emissions, which will include both the initial value and incremented values. Try emitting Observable.range(5,10), and you will notice that it emits 5 followed by the next nine consecutive integers following it (for a grand total of 10 emissions):

    import io.reactivex.Observable;

public class Launcher {
public static void main(String[] args) {
Observable.range(5,10)
.subscribe(s -> System.out.println("RECEIVED: " + s));

}
}

The output is as follows:

    RECEIVED: 5
RECEIVED: 6
RECEIVED: 7
RECEIVED: 8
RECEIVED: 9
RECEIVED: 10
RECEIVED: 11
RECEIVED: 12
RECEIVED: 13
RECEIVED: 14
Note that there is also a long equivalent called Observable.rangeLong() if you need to emit larger numbers.
主站蜘蛛池模板: 滕州市| 湘潭县| 房产| 神木县| 宁陕县| 安多县| 永善县| 卓尼县| 博乐市| 堆龙德庆县| 乌拉特前旗| 玉山县| 西丰县| 鄂托克前旗| 扶余县| 乐都县| 浏阳市| 诏安县| 新宾| 京山县| 广灵县| 息烽县| 柳河县| 宜春市| 富宁县| 阜城县| 泸定县| 丰镇市| 龙泉市| 石渠县| 马关县| 安乡县| 思茅市| 琼海市| 甘谷县| 蓝田县| 潮安县| 丁青县| 济宁市| 郧西县| 临沂市|