import java.util.*;
public class Demo2 {
public static void main(String[] args) {
TreeSet ts = new TreeSet(new Comparator(){
public int compare(Object o1,Object o2){
int i = o1.toString().length() - o2.toString().length();
if(i==0) {
i = o1.toString().compareTo(o2.toString());
}
return i;
}
});
ts.add("aaaa");
ts.add("aa");
ts.add("aab");
//加入长度一致就错啦。。。
ts.add("aaa");
Iterator it = ts.iterator();
while(it.hasNext()){
System.out.println(it.next().toString());
}
}
}
|
|