import java.util.Comparator; import java.util.Iterator; import java.util.TreeSet; public class TreeSetDemo2 { public static void main(String[] args) { TreeSet<String> ts=new TreeSet(); ts.add("a"); ts.add("sfsd"); ts.add("fgdfd"); ts.add("aaa"); ts.add("bcd"); Iterator<String> it=ts.iterator(); while(it.hasNext()) { System.out.println(it.next()); } } } class StringLengthCompare implements Comparator<Object> { public int compare(Object o1,Object o2) { String s1=(String) o1; String s2=(String) o2; int num=new Integer(s1.length()).compareTo(new Integer(s2.length())); if(num==0) return s1.compareTo(s2); return num; } }
出现在int num=new Integer(s1.length()).compareTo(new Integer(s2.length()));这一行
白衣染霜花
人到中年有点甜
相关分类