package com.itheima;
import java.util.*;
public class TrSet {
public static void main(String[] args){
TreeSet<String> t=new TreeSet<String>(new MyComparator());
t.add("jik");
t.add("k");
t.add("kuii");
t.add("jo");
Iterator<String> it=t.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
}
class MyComparator implements Comparator{
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;
}
}
如上面程序。系统为什么提示我MyComparator出错了,它不是类名?按自己的习惯定义吗????
|
|