--过滤
List<Object> listNew=list.stream().filter(s->s.getWorkpost().equals(ErpWorkpostType.DRIVER)).collect(Collectors.toList());
--分组排序
public void groupByBusGroupNew(List<ScheduleShiftsListVo> shifts) {
//班次分组排序
LinkedHashMap<Long,LinkedHashMap<Long, List<ScheduleShiftsListVo>>> resMapShifts = shifts.stream() .collect(Collectors.groupingBy(ScheduleShiftsListVo::getBusGroupId, LinkedHashMap::new, Collectors.groupingBy(ScheduleShiftsListVo::getBusGroupId, LinkedHashMap::new, Collectors.toList())));
Iterator<Map.Entry<Long, LinkedHashMap<Long, List<ScheduleShiftsListVo>>>> iteratorLinkMapShifts =resMapShifts.entrySet().iterator();
shifts.clear();
while (iteratorLinkMapShifts.hasNext()) {
Map.Entry<Long, LinkedHashMap<Long, List<ScheduleShiftsListVo>>> entry = iteratorLinkMapShifts.next();
LinkedHashMap<Long, List<ScheduleShiftsListVo>> val = entry.getValue();
Iterator<Map.Entry<Long, List<ScheduleShiftsListVo>>> iteratorList = val.entrySet().iterator();
while (iteratorList.hasNext()) {
Map.Entry<Long, List<ScheduleShiftsListVo>> listDetail = iteratorList.next();
shifts.addAll(listDetail.getValue());
}
}
}
--获取某一个属性
List<Long> svId=planList.stream().map(ExecutablePlan::getBusGroupId).distinct().collect(Collectors.toList());
--list转map且重复数据覆盖
Map<String, String> nowEmployeeMap=ssdList.stream().collect(Collectors.toMap(ScheduleStaffDetailTarget::getDriverNumber, ScheduleStaffDetailTarget::getDriverName,(v1, v2) -> v1));
--list转map某一属性为key,实体类为value,分别为重复不覆盖、覆盖,重复不覆盖,当存在重复时候会异常
Map<String, Object> erpEmployeeMap = employeeVoList.stream().collect(Collectors.toMap(EmployeeDetail::getEmployee_code, EmployeeVo -> EmployeeVo));
Map<String,ExecutablePlan> vehicles=newPlanList.stream().collect(Collectors.toMap(ExecutablePlan::getVehicleCode, ExecutablePlan->ExecutablePlan,(v1,v2)->v1));
private List<Integer> list;
Map<Integer, String> userTextRule = list.stream().collect(HashMap::new, (k, v) -> k.put(v, "0"), HashMap::putAll);
--排序
List<Object> listnew=drivers.stream().sorted(Comparator.comparing(RoutePlanDriverVo::getFirstTime)).collect(Collectors.toList())
--类型转换List<String>转List<Integer>
List<Integer> listNew=lineNodeList.stream().map(item -> Integer.parseInt(item)).collect(Collectors.toList())
--字符串转数组
String rs="123,456,785";
Integer[] rule= Splitter.on(",").trimResults().splitToList(rs)
.stream().map(Integer::valueOf).toArray(Integer[]::new);
--求和
dmList.stream().filter(s -> s.getEmployeeNumber().equals(d.getDriverNumber())).count()
--替换某一个元素值
List<Object> newList=ruleConfigList.stream().map(s->{s.setRuleId(newRuleId);s.setNd(DateUtils.getYear());return s;}).collect(Collectors.toList())
--字符数组转List<Integer>
String scriptsManVehicleBinding="0,11,12,13,14,15,16,17,18,19,20";
List<Integer> lastScripts= IntStream.of(Arrays.asList(scriptsManVehicleBinding.split(",")).stream().mapToInt(Integer::valueOf).toArray()).boxed().collect(Collectors.toList());
--统计
list.stream().mapToDouble(SettlementDrivingRecord::getRealMileage).sum()
--获取最大某个属性
drivingRecordList.stream().max(Comparator.comparing(SettlementDrivingRecord::getShiftOrder)).get().getShiftOrder();