package com.heima.test;
import java.util.Comparator;
import java.util.TreeSet;
public class Test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
TreeSet<String> ts = new TreeSet<>(new CompareBy());
ts.add("zhansan");
ts.add("lisi");
ts.add("wangwu");
ts.add("zhaoliu");
}
class CompareBy implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
// TODO Auto-generated method stub
int num = o1.length()-o2.length();
return num == 0 ? o1.compareTo(o2): num;
}
}
}
为什么会报错啊?
|
|