I\'m trying to sort my custom class chromosome by the value of their score attribute which is a double. These chromosomes are stored within an ArrayList. I know I have to us
To use a Comparator:
Collections.sort(myList, new Comparator() {
@Override
public int compare(Chromosome c1, Chromosome c2) {
return Double.compare(c1.getScore(), c2.getScore());
}
});
If you plan on sorting numerous Lists in this way I would suggest having Chromosome implement the Comparable interface (in which case you could simply call Collections.sort(myList), without the need of specifying an explicit Comparator).