//升序排列
Collections.sort(list, new Comparator<Student>() {
public int compare(Student s1, Student s2) {
return s1.getAge().compareTo(s2.getAge());
}
});
//降序排列
Collections.sort(list, new Comparator<Student>() {
public int compare(Student s1, Student s2) {
return s2.getAge().compareTo(s1.getAge());
}
});
//使用下面需要JDK1.8及以上
//升序排列
list.sort((x,y)->Integer.compare(x.getAge(), y.getAge()));
//降序排列
list.sort((x,y)->Integer.compare(y.getAge(), x.getAge()));