I have an array list consisting of objects defined in the class Result(date, name, grade). I have managed to sort the dataset. However I want there to be no duplicates, only the object with that has highest grade attribute should be left. I have tried several codes but it gets me no where.
The data looks as following now,
DATE NAME GRADE
0612 AA BB 15
0713 AA BB 12
0613 CD E 7
0327 KA BC 23
0903 KA BC 15
But i want it to look like this
0612 AA BB 15
0613 CD E 7
0327 KA BC 23
Result class defined as below
Result(int date,String name, String grade){
this.date=date;
this.name=first;
this.grade=grade;
}
for (Result element:info) {
if (!newList.contains(element.name)) {
newList.add(element);
}
}
for(Result st:newList){
System.out.println(st.date+" "+st.name+" " + st.grade);
}
}
}
I have done this, so far. However it does not give me the wanted output.