import java.util.Comparator; class PersonComparator implements Comparator { public int compare(Person o1, Person o2) { // here, we're just going to compare the first // letter of the two names; let's assume for now // that neither name is the empty string int diff = o1.name.charAt(0) - o2.name.charAt(0); // remember, chars are actually numbers! if (diff < 0) { return -1; // o1 comes first } else if (diff == 0) { return 0; // o1 and o2 have the same first letter } else { return 1; // o2 must come first } } }