如果是要让一个对象可比较,那么需要实现该对象中的Comparable接口,重写里面的compareTo()方法。
ArrayList<Integer> list = new ArrayList<Integer>();
Collctions.sort(list,new Comparator<Integer>(){
public int compare(Integer str1,Integer str2){
String s1 = str1+""+str2;
String s2 = str2 +""+str1;
return s1.compareTo(s2);//String 中的compareTo方法是为了按字典顺序比较两个字符串。
}
}