Check if one list contains element from the other

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

    You can use Apache Commons CollectionUtils:

    if(CollectionUtils.containsAny(list1,list2)) {  
        // do whatever you want
    } else { 
        // do other thing 
    }  
    

    This assumes that you have properly overloaded the equals functionality for your custom objects.

提交回复
热议问题