java去除兩個集合中重復的數據?
List<String> stuList3 = new ArrayList<String>(); stuList3.addAll(stuList); stuList3.addAll(stuList2);//把兩個集合合成一個 stuList.retainAll(stuList2);//找出兩個集合中重復的數據 stuList3.removeAll(stuList);//然后移除 for(String s: stuList3){ System.out.println(s);//打印結果 }