// Erika Wolfe, CSE 143 // Examples showing how to order objects and collections. import java.util.*; public class CollectionsOrdering { public static void main(String[] args) { testStringOrdering(); testCatOrdering(); } // Prints a phrase, then prints it again in alphabetical order public static void testStringOrdering() { List words = Arrays.asList("java", "knows", "how", "to", "sort", "these", "words"); System.out.println(words); Collections.sort(words); System.out.println(words); } // prints cats in sorted order public static void testCatOrdering() { List cats = new ArrayList(); cats.add(new Cat("Grumpy", 0, 14.5)); cats.add(new Cat("Clawdia", 9, 13)); cats.add(new Cat("Lily", 6, 50.3)); cats.add(new Cat("Ginger", 3, 10)); cats.add(new Cat("Gato", 5, 16.2)); cats.add(new Cat("Shakespurr", 6, 20.0)); cats.add(new Cat("Hairy", 8, 18.0)); cats.add(new Cat("Casper", 7, 12)); cats.add(new Cat("Mac", 6, 20.0)); System.out.println(cats); Collections.sort(cats); System.out.println(cats); } }