iimport java.util.*; public class NameSortedSet { static final Comparator NameOrdering = new Comparator() { public int compare(Name n1, Name n2) { int cmp = n1.firstName().compareTo(n2.firstName() ); return (cmp != 0 ? cmp : n1.lastName().compareTo(n2.lastName() )); } }; public static void main(String[] args) { SortedSet names = new TreeSet(NameOrdering); names.add(new Name("Bob", "Travolta")); names.add(new Name("John", "Smith")); names.add(new Name("Karl", "Ng")); names.add(new Name("Jeff", "Smith")); names.add(new Name("Tom", "Rich")); for(Name n: names) System.out.println(n); System.out.println("\n***Print headset***"); SortedSet subnames = names.headSet(new Name("Karl", "Ng")); for(Name n: subnames) System.out.println(n); System.out.println("\n***Print tailset***"); subnames = names.tailSet(new Name("Karl", "Ng")); for(Name n: subnames) System.out.println(n); } }