I have a ArrayList of CustomObject, my object is simply made of two values x and y
MyObject = (double)x && (double)y
What I want to do is:
- remove duplicate from array : simply remove duplicate object and if the objects have the same x keep the one if the higher y.
- reorder the list depending on the x value (x is for the time, y is a factor)
I have tried using Collections.sort
to reorder my array and using a set to remove duplicate but nothing works.
Collections.sort(listPoints, new Comparator<MyObject>(){
@Override
public int compare(MyObject lhs, MyObject rhs) {
return Double.compare(lhs.y, rhs.y);
}
});
Collections.sort(listPoints, new Comparator< MyObject >(){
@Override
public int compare(MyObject lhs, MyObject rhs) {
return Double.compare(lhs.x, rhs.x);
}
});