對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