Check if one list contains element from the other

前端 未结 12 2640
没有蜡笔的小新
没有蜡笔的小新 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:43

    Loius answer is correct, I just want to add an example:

    listOne.add("A");
    listOne.add("B");
    listOne.add("C");
    
    listTwo.add("D");
    listTwo.add("E");
    listTwo.add("F");      
    
    boolean noElementsInCommon = Collections.disjoint(listOne, listTwo); // true
    

提交回复
热议问题