对list集合中对象的多个属性按一定顺序排序

Collections.sort(list, new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
int result = 0;
if (o1.getExta().equals("200")) {
result = -1;
}
if (o2.getExta().equals("200")) {
result = 1;
}
if (result != 0)
return result;

if (o1.getIsPriority() == 1) {
result = -1;
}
if (o2.getIsPriority() == 1) {
result = 1;
}
if (result != 0)
return result;

result = o1.getSort() - o2.getSort();
if (result != 0)
return result;

result = o2.getRating() - o1.getRating();
if (result != 0)
return result;

result = o2.getTiming() - o1.getTiming();
return result;
}
});
原文地址:https://www.cnblogs.com/sam-cheng/p/6378589.html