对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;
}
});
posted @ 2017-02-08 15:54  samcheng  阅读(2979)  评论(0编辑  收藏  举报