import java.util.*;

public class UseComparator {
  
  public static void main(String[] args) throws java.io.IOException {
    String[] names = { "Sue", "Bill", "Tom", "Dave", "Andy",
                       "Mary", "Beth", "Bill", "Mike" };

    TreeSet<String> ts1 = new TreeSet<>(new ReverseComparator<String>());
    ts1.addAll(Arrays.asList(names));
    
    for (String name : ts1) {
       System.out.println(name);
    }
  }
}

class ReverseComparator<T> implements Comparator<T> {
  public int compare(T o1, T o2) {
    if (o1 instanceof String && o2 instanceof String) {
       return -((String)o1).compareTo((String)o2);
    }
    else {
		   throw new ClassCastException("Objects are not Strings");
	  }
  }
}