* Animals by their animal class. Order doesn't matter, but we want to
* ensure that animals are grouped by their animal class property.
*/
Arrays.sort(animals, new Comparator() {
public int compare(Object t, Object t1) {
Animal firstAnimal = (Animal) t;
Animal secondAnimal = (Animal) t1;
return firstAnimal.getAnimalClass().hashCode() -
secondAnimal.getAnimalClass().hashCode();
}
});
for (Animal animal : animals) {
System.out.println(animal.toString());