java List排序

简介:

private void sortListByPriority(List resultList) {

    if (null != resultList && resultList.size() > 0) {
        Collections.sort(resultList, new Comparator<JSONObject>() {
            public int compare(JSONObject p1, JSONObject p2) {
                int returnNum = 0;
                if (null != p1 && null != p2) {
                    String priority1 = (String) p1.get("priority");
                    String priority2 = (String) p2.get("priority");
                    if (StringUtils.isNotBlank(priority1) && StringUtils.isNotBlank(priority2)) {
                        int tempP1 = Integer.parseInt(priority1);
                        int tempP2 = Integer.parseInt(priority2);
                        returnNum = tempP2 - tempP1;
                    }
                }
                return returnNum;
            }
        });
    }
}
相关文章
|
1月前
|
存储 安全 Java
java集合框架及其特点(List、Set、Queue、Map)
java集合框架及其特点(List、Set、Queue、Map)
|
21天前
|
Java
java8中List对象转另一个List对象
java8中List对象转另一个List对象
36 0
java.lang.Error: Unresolved compilation problem: The type List is not generic; it cannot be parame
java.lang.Error: Unresolved compilation problem: The type List is not generic; it cannot be parame
|
18天前
|
Java
Java使用List去重的四中方式
Java使用List去重的四中方式
16 6
|
22天前
Cause: java.sql.SQLIntegrityConstraintViolationException: Column ‘id‘ in field list is ambiguous
Cause: java.sql.SQLIntegrityConstraintViolationException: Column ‘id‘ in field list is ambiguous
12 0
|
1月前
|
Java
JAVA——List中剔除空元素(null)的三种方法汇总
JAVA——List中剔除空元素(null)的三种方法汇总
|
1月前
|
安全 Java API
Java并发 - J.U.C并发容器类 list、set、queue
Queue API 阻塞是通过 condition 来实现的,可参考 Java 并发 - Lock 接口 ArrayBlockingQueue 阻塞 LinkedBlockingQueue 阻塞 ArrayQueue 非阻塞 LinkedQueue 非阻塞
|
1月前
|
Java
如何使用 Java 8 进行字符串排序?
【2月更文挑战第21天】
66 3
|
1月前
|
搜索推荐 算法 C++
list容器-排序案例讲解
list容器-排序案例讲解
9 0
|
1月前
|
算法 C++ 容器
list容器-反转和排序讲解39
list容器-反转和排序讲解39
12 0