I've got this class called Block (each Block has an x value and a y value). I've created a bunch of these and put them all in a list. I've managed to sort the list by x-value:
public class Block implements Comparable<Block> {
...
public int compareTo(Block block2){
return this.x - block2.x;
}
But I want to be able to sort the list both by x and by y-value at my leisure. Is this doable somehow?
Comparator<Block>instead of the defaultcompareTo(method)(and of course the rightsortmethod that uses theComparator<Block>)