java map list过滤
2026/9/16 14:11:26 网站建设 项目流程
// map xx+yy形式Map<String,VehicleRecordNumVO>vehicleRecordNumVOMap=vehicleRecordNumVOList.stream().collect(Collectors.toMap(v->v.getAppletUserId()+"-"+v.getVehiclePlate(),vehicleRecordNumVO->vehicleRecordNumVO));// map xx形式Map<String,MyVehicle>myVehicleMap=myVehicleList.stream().collect(Collectors.toMap(MyVehicle::getPlateNum,myVehicle->myVehicle));Map<String,List<MyVehicle>>myVehicleMap=myVehicleList.stream().collect(Collectors.groupingBy(MyVehicle::getAppletUserId));// list过滤List<EnterpriseCarInfo>uniqueMyVehicleList=uniqueList.stream().collect(Collectors.toMap(v->v.getPlateNum()+"_"+v.getVehicleColor(),// 作为唯一 keyv->v,(existing,replacement)->existing// 如果重复,保留第一个)).values().stream().collect(Collectors.toList());Map<String,Refund>refundMap=refundList.stream().collect(Collectors.toMap(Refund::getOutTradeNo,refund->refund,(existing,replacement)->replacement// 遇到重复key时,保留新值(覆盖旧值)));
importjava.text.Collator;importjava.util.Locale;// 查询后手动排序List<PersonalPerformance>result=repository.findBySectionDeptIdAndMonthAndUserIdInAndDelFlag(sectionDeptId,month,userIds,delFlag);// 使用中文拼音排序Collatorcollator=Collator.getInstance(Locale.CHINA);result.sort((a,b)->{intscoreCompare=Integer.compare(b.getScore(),a.getScore());// descif(scoreCompare!=0)returnscoreCompare;returncollator.compare(a.getUserName(),b.getUserName());// 拼音升序});

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询