I have an ArrayList containing CoolMove elements and want to sort it by the values CoolMove.getValue() returns (these values are Doubles). I read that you can sort using a comparator class and in an attempt to do this I made the following:
I have 2 classes, one having these code lines:
ArrayList<CoolMove> moveList = getMoves();
Arrays.sort(fishMoves, new myComp());
My 2nd class is this comparator:
class myComp implements Comparator<CoolMove> {
@Override
public int compare(CoolMove move1, CoolMove move2) {
return Double.compare(move1.getValue(), move2.getValue());
}
}
My problem is that at Arrays.sort I get this error: The method sort(T[], Comparator) in the type Arrays is not applicable for the arguments (ArrayList, myComp) How can I fix this?