Check if one list contains element from the other

前端 未结 12 2629
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 20:45

I have two lists with different objects in them.

List list1;
List list2;

I want to check if element from list

12条回答
  •  暖寄归人
    2020-11-30 21:23

    With java 8, we can do like below to check if one list contains any element of other list

    boolean var = lis1.stream().filter(element -> list2.contains(element)).findFirst().isPresent();
    

提交回复
热议问题