Lambda in Stream.map/filter not called

后端 未结 4 934
执笔经年
执笔经年 2021-01-18 04:56

I\'m trying to find separate the duplicates and non-duplicates in a List by adding them to a Set and List while using Stream.fil

4条回答
  •  情话喂你
    2021-01-18 05:22

    There is a more elegant way to use the filter with Predicate negate() method instead of using logical operator !

    List extras = strings
    .stream()
    .filter(((Predicate) distinct::add).negate())
    .peek(System.out::println)
    .collect(Collectors.toList());
    

    peek is a function used for pipeline debugging only.

提交回复
热议问题