public class ListUtils<T> {
/**
* 获取两个list的差集
* @param totalList 总的List
* @param containsList 要排除的list
* @return totallist - containsList
*/
public List<T> getTwoListDifference(List<T> totalList,List<T> containsList){
HashMap<T, Boolean> map = new HashMap(0);
for (int i = 0; i < containsList.size(); i++) {
map.put(containsList.get(i), true);
}
containsList.clear();
for (int i = 0; i < totalList.size(); i++) {
if (!map.containsKey(totalList.get(i))) {
containsList.add(totalList.get(i));
}
}
return containsList;
}
}
获取两个list的差集方法
最新推荐文章于 2024-07-03 03:47:54 发布