filter(过滤操作符)

目录

1 filter作用

2 filter接口

3 filter图解说明

4 filter测试用例


 

1 filter作用

通过指定的条件来过滤发布者发出的项。

 

2 filter接口

Flowable<T> filter(Predicate<? super T> predicate)

Filters items emitted by a Publisher by only emitting those that satisfy a specified predicate.

通过指定的条件来过滤发布者发出的项。

 

3 filter图解说明

RxJava2 Flowable filter (过滤操作符)

会过滤掉值小于10的项

 

4 filter测试用例

测试用例中会过滤掉源Publisher发射的非item1和item7的项目

 @Test
    public void filter() {
        System.out.println("######filter#####");
        Flowable.just("item2", "item1", "item7", "item8", "item9").filter(new Predicate<String>() {
            @Override
            public boolean test(String s) throws Exception {
                return s.equals("item1") || s.equals("item7");
            }
        }).subscribe(new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                System.out.println("s = " + s);
            }
        });
    }


测试输出
######filter#####
s = item1
s = item7

 

相关文章:

  • 2021-08-27
  • 2021-06-15
  • 2021-06-02
  • 2021-05-28
  • 2021-04-17
  • 2022-12-23
  • 2021-04-04
  • 2021-12-30
猜你喜欢
  • 2021-12-16
  • 2021-04-07
  • 2021-09-07
  • 2021-12-03
  • 2021-06-26
  • 2022-01-16
  • 2021-11-28
相关资源
相似解决方案