<1>对List<T>排序:
T 实现comparable接口,重写 compareTo 方法
调用collections.sort(list);
<2>使用比较器Comparator
Collections.sort(studentArr, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
Student s1 = (Student) o1;
Student s2 = (Student) o2;
if(){reutrn 1};
else if(){return -1};
return 0;
}
});
时间: 2024-11-04 22:15:58