import java.util.*;
public class TestTreeSet{ public static void main(String[] args){ //Comparator的实现类型是TreeSet里实际类型的父类,满足要求 TreeSet<String> ts1=new TreeSet<String>(new Comparator<Object>(){ public int compare(Object fst,Object snd){ return fst.hashCode()-snd.hashCode(); } } ); ts1.add("a"); ts1.add("b"); TreeSet<String> ts2=new TreeSet<String>( new Comparator<String>(){ public int compare(String fst,String snd){ return -(fst.length()-snd.length()); } } ); ts2.add("a"); ts2.add("cx"); System.out.println(ts1); System.out.println(ts2); String a="a"; String b="b"; System.out.println(a.hashCode()); System.out.println(b.hashCode()); }}