对List集合内的对象按时间降序排列

list = list.stream().sorted(Comparator.comparing(实体::排序字段).reversed()).collect(Collectors.toList());

案例

List<ServiceRecord> recorderList = new ArrayList<>();
        for (ServiceOrder order : orderList){
    
    
            List orderLists = this.iServiceRecordService.list(new QueryWrapper<ServiceRecord>().lambda().eq(ServiceRecord::getOrderId, order.id));
            for(Object record : orderLists){
    
    
                recorderList.add((ServiceRecord) record);
            }
        }
 recorderList = recorderList.stream().sorted(Comparator.comparing(ServiceRecord::getCreateTime).reversed()).collect(Collectors.toList());

另一种方法(整形为例)

resultList.sort(Comparator.comparingInt(ServiceInfoItemResultAudit::getSortNum));

猜你喜欢

转载自blog.csdn.net/qq_45924975/article/details/121050110