RxJava2 Flowable isEmpty 條件操作符

 

目錄

 

isEmpty

1 接口

2 圖解和說明

3 測試用例


isEmpty

接口

Single<Boolean>

 

 

isEmpty()

Returns a Single that emits true if the source Publisher is empty, otherwise false.

返回一個Single,如果源Publisher爲空,則返回true,否則返回false。

 

 

2 圖解和說明

 

 

3 測試用例

 @Test
    public void isEmpty() {
        System.out.println("######isEmpty#####");
        System.out.println("test 1");
        Flowable.empty().isEmpty().subscribe(new Consumer<Boolean>() {
            @Override
            public void accept(Boolean aBoolean) throws Exception {
                if(aBoolean) {
                    System.out.println("is empty");
                } else {
                    System.out.println("no empty");
                }
            }
        });

        System.out.println("test 2");
        Flowable.just(1).isEmpty().subscribe(new Consumer<Boolean>() {
            @Override
            public void accept(Boolean aBoolean) throws Exception {
                if(aBoolean) {
                    System.out.println("is empty");
                } else {
                    System.out.println("no empty");
                }
            }
        });


    }


######isEmpty#####
test 1
is empty
test 2
no empty

測試結果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章