本帖最后由 插兜 于 2015-9-30 21:50 编辑
- import java.util.*;
- class GenericDemo
- {
- public static void main(String[] args)
- {
- ArrayList<String> al=new ArrayList<String>(new LenComparator());
- al.add("abc");
- al.add("acvd");
- al.add("d");
- Iterator<String> it=al.iterator();
- while(it.hasNext())
- {
- String s=it.next();
- System.out.println(s);
- }
- //System.out.println("Hello World!");
- }
- }
- class LenComparator implements Comparator<String>
- {
- public int compare(String o1,String o2)
- {
- int num=new Integer(o1.length()).compareTo(new Integer(o2.length()));
- if(num==0)
- return o1.compareTo(o2);
- return num;
- }
- }
复制代码
我按照毕老师写的,但怎么编译不过呢
|
|