iterating and filtering two lists using java 8

后端 未结 9 502
抹茶落季
抹茶落季 2020-12-09 17:21

I want to iterate two lists and get new filtered list which will have values not present in second list. Can anyone help?

I have two lists - one is list of strings,

9条回答
  •  一生所求
    2020-12-09 17:53

    Doing it with streams is easy and readable:

    Predicate notIn2 = s -> ! list2.stream().anyMatch(mc -> s.equals(mc.str));
    List list3 = list1.stream().filter(notIn2).collect(Collectors.toList());
    

提交回复
热议问题