private List<Long> orderByAsc(List<Long> scores){
for (int i = 0; i < scores.size() - 1; i++) {
for (int j = 1; j < scores.size() - i; j++) {
Long a;
if ((scores.get(j - 1)).compareTo(scores.get(j)) > 0) {
a = scores.get(j - 1);
scores.set((j - 1), scores.get(j));
scores.set(j, a);
}
}
}
return scores;
}
方式二:
public class ComparatorComment implements Comparator {
public int compare(Object arg0, Object arg1) {
CommentInfoBean comment0 = (CommentInfoBean) arg0;
CommentInfoBean comment1 = (CommentInfoBean) arg1;
// 按score降序
if (comment0.getScore() < comment1.getScore()) {
return 1;
} else {
return 0;
}
}}
List list = resultPage.getResult();
ComparatorComment comparator = new ComparatorComment();
Collections.sort(list, comparator);
resultPage.setResult(list);