java List 对象排序

//departmentList为集合字段 例如List
Collections.sort(departmentList, (mode1, mode2) -> {
            //mode1.getPriority为对象里要用到的排序字段
            int priority1 = mode1.getPriority();
            int priority2 = mode2.getPriority();
            //设置优先级小的在前大的在后例如1.2.3.4
            if (priority1 < priority2) {
                return 1;
            } else if (priority1 == priority2) {
                return 0;
            } else {
                return -1;
            }
        });
 

                            
                        
                    
                    
                    

你可能感兴趣的:(java List 对象排序)