刪除重複的對象我有一個Java類從ArrayList中
class Students{
private String fName;
private String lName;
private String uName;
public Students(String fName, String lName, String uName) {
this.fName = fName;
this.lName = lName;
this.uName = uName;
}
public String getuName() {
return uName;
}
public void setuName(String uName) {
this.uName = uName;
}
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
public String getlName() {
return lName;
}
public void setlName(String lName) {
this.lName = lName;
}
}
現在我必須爲創建的對象;
Students students1 = new Students("har","mat","harmat");
Students students2 = new Students("pan","son","panson");
Students students3 = new Students("yogi","jos","yogijos");
Students students4 = new Students("har","mat","harmat");
Students students5 = new Students("pan","son","harmat");
Students students6 = new Students("yogi","jos","someotherUName");
Students students7 = new Students("yogi","jos","someotherUName2");
現在,所有這些對象加入到combinedList
List combinedList = new ArrayList<SchoolStudents>();
我想從基於以下標準這combinedList刪除重複的對象; 如果fName相同或者uName相同。
[數組列表中查找重複的值]的可能重複(http://stackoverflow.com/questions/7281352/finding-duplicate-values-in-arraylist) – 2012-07-25 14:13:52
然後,多個副本的http://計算器.com/questions/4778260/how-to-remove-arraylist-duplicate-values,http://stackoverflow.com/questions/9962082/prevent-duplicate-entries-in-arraylist,http://stackoverflow.com/questions/5181821/would-like-to-avoid-duplicate-entries-in-a-arraylist,http://stackoverflow.com/questions/5754592/finding-index-of-duplicate-values-in-an-arraylist,http ://sackoverflow.com/questions/5503646/find-duplicate-objects-in-an-java-arraylist – 2012-07-25 14:14:22
作業?你試過什麼了?提示:使用可比較的(),也許設置 – maasg 2012-07-25 14:14:41