List sort 排序

正序:

 1 resultList.sort((o1, o2) -> {
 2     //正序
 3     double diff = o1.getNum() - o2.getNum();
 4     if (diff > 0) {
 5         return 1;
 6     }else if (diff < 0) {
 7         return -1;
 8     }
 9     return 0;
10 }); 

倒序:

resultList.sort((o1, o2) -> {
    //倒
    double diff = o2.getNum() - o1.getNum();
    if (diff > 0) {
        return 1;
    }else if (diff < 0) {
        return -1;
    }
    return 0;
}); 

 

posted @ 2021-04-25 09:28  爱,诗意永存  阅读(163)  评论(0编辑  收藏  举报