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
Why not use a PriorityQueue with a Comparator like this:
// your code
PriorityQueue entries = new PriorityQueue(1, new Comparator () {
@Override
public int compare(Chromosome arg0, Chromosome arg1) {
return (Double)(arg1.getScore()).compareTo((Double)arg0.getScore());
}
});
entries.addAll(arrayListOfChromosomes);
// your code
The priority queue will then keep your data structure in sorted order.