import java.util.*; class ClassA implements Comparable { private int value; ClassA(int value){ this.value = value; } public int compareTo(ClassA ca){ return value - ca.value; } @Override public int hashCode(){ return value; } @Override public boolean equals(Object o){ return value == ((ClassA)o).value; } public int getValue(){ return value; } } class Samp15 { public static void main(String[] args){ Comparator ca = Collections.reverseOrder(); System.out.println(ca.getClass().getName()); TreeSet tsa = new TreeSet(ca); tsa.add(new ClassA(30)); tsa.add(new ClassA(20)); tsa.add(new ClassA(10)); for(ClassA c: tsa){ System.out.println(c.getValue()); } } }