有一个List<String> idList存着很多ID(String)现在有两个List,分别是List<Company>和List<Organization>,存的是许多Company和Organization的Object而Company和Organization的Object里面,包括一个客户ID的List,List<Client_ID>如何高效地判断idList里面的ID在不在Company和Organization的Client_ID里面?
调试欢乐多
Returns true if this list contains the specified element.
boolean containsAll(Collection<?> c)
Returns true if this list contains all of the elements of the specified collection.
List<String> idList = aaa;
List<Company> cmpList = xxx;
List<Organization> orgList = yyy;
for (Company c : cmpList) {
List<String> list = new ArrayList(c.getClientId());
int size = list.size();
list.removeAll(idList);
if (size == list.size()) {
System.out.println("contains id in idList");
}
}
for (Organization o : orgList) {
//和上面处理相似
}
cmpList的client_id_list和idList作差处理,如果size发生了变化,就说明和idList有重复才会被差掉的,所以可以判断
当然,用两个集合的交集判断也可以,即
cmpList的client_id_list.retainsAll(idList),如果交集的size为0,说明没有交集,也就是不包含idList