对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;
}
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM