从两个List集合里找到相同部分和不同部分

/**
 * 获取两个集合里元素不同的部分
 */
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