当前位置: 首页 > 工具软件 > ReJava > 使用案例 >

ReJava操作符 distinct 、Filter

秦权
2023-12-01
distinct
         这个操作符非常的简单、通俗、易懂,就是简单的去重嘛
         Observable.just(1,2,3,4,5,1).distinct().subscribe(new Consumer<Integer>() {
        @Override
         public void accept(Integer integer) throws Exception {
         Log.e("55555555555", "distinct : " + integer + "\n");
          }
         });
09-05 20:27:26.939 12107-12107/com.vise.snowdemo E/55555555555: distinct : 1
09-05 20:27:26.939 12107-12107/com.vise.snowdemo E/55555555555: distinct : 2
09-05 20:27:26.939 12107-12107/com.vise.snowdemo E/55555555555: distinct : 3
09-05 20:27:26.939 12107-12107/com.vise.snowdemo E/55555555555: distinct : 4
09-05 20:27:26.939 12107-12107/com.vise.snowdemo E/55555555555: distinct : 5
Filter
        Filter 也很简单,过滤器嘛。可以接受一个参数,让其过滤掉不符合我们条件的值
        Observable.just(1, 20, 65, -5, 7, 19)
        .filter(new Predicate<Integer>() {
            @Override
            public boolean test(@NonNull Integer integer) throws Exception {
                return integer >= 10;
            }
        }).subscribe(new Consumer<Integer>() {
      @Override
      public void accept(@NonNull Integer integer) throws Exception {
  
     
    }
});

 类似资料: