import java.util.Comparator; /** FitnessComparator.java - I think I want to sort the fitness in * descending order. So, we need to switch the order of subtraction * because we are accustomed to sort in ascending order. */ public class FitnessComparator implements Comparator { public int compare(Object o1, Object o2) { Individual i1 = (Individual) o1; Individual i2 = (Individual) o2; // Reverse the difference because we want descending sort. return -(i1.findFitness() - i2.findFitness()); } }