import java.util.Arrays; import java.util.Comparator; public class ArraySort { public static void main(String[] args) { Dog d2 = new Dog(2); Dog d1 = new Dog(1); Dog d3 = new Dog(3); Dog[] dogArray = {d3,d1,d2}; printDog(dogArray); Arrays.sort(dogArray,new DogSizeComparator()); printDog(dogArray); } public static void printDog(Dog[] dogs){ for (Dog dog:dogs) { System.out.println(dog.size+" "); } System.out.println(); } } class Dog{ int size; public Dog(int s){ this.size = s; } } class DogSizeComparator implements Comparator{ @Override public int compare(Dog o1, Dog o2) { return o1.size - o2.size; } }