Hi everyone,
I just want to use Collections.sort or Arrays.sort to sort a list of points (class Point) by x first and then by y.
I have a class Ponto that implements Comparable like this:
public int compareTo(Ponto obj) {
Ponto tmp = obj;
if (this.x < tmp.x) {
return -1;
} else if (this.x > tmp.x) {
return 1;
}
return 0;
}
but now I want to sort by y too after x.
How can I do that by modifying the above code? Or is that a better and "clean" way to do this? I also use to pass this code to C++, in which I've created a structure called Point with a equivalent comparable method.