/**
* 获取两个集合里元素不同的部分
*/
public List<User> getDifferent(List<User> u1, List<User> u2) {
//定义两个空集合
List<User> allUsers = new ArrayList<>();
List<User> differentUsers = new ArrayList<>();
allUsers.addAll(u1);
allUsers.addAll(u2);
for (int i = 0; i < allUsers.size(); i++) {
if (u1.contains(allUsers.get(i)) && u2.contains(allUsers.get(i))) {
continue;
} else {
differentUsers.add(allUsers.get(i));
}
}
return differentUsers;
}
原文地址:https://www.cnblogs.com/baijinqiang/p/11972418.html
时间: 2024-11-13 08:14:07