Java 8 lambda predicate chaining?

前端 未结 6 1687
渐次进展
渐次进展 2020-12-08 19:30

I can\'t get it to compile, is it even possible to chain predicate lambdas?

Arrays.asList(\"1\",\"2\",\"3\").stream().filter( (e -> e==\"1\" ).or(e-> e         


        
6条回答
  •  [愿得一人]
    2020-12-08 20:01

    Predicate pred1 =  "1"::equals;
    Predicate pred2 =  "2"::equals;
    
    public void tester(){
          Arrays.asList("1","2","3").stream().filter(pred1.or(pred2)).count();
    }
    

    You can move your separate your conditions to make it possible to recombine them other ways.

提交回复
热议问题