stream语法简单使用
排序
seriesMap.keySet().stream().
sorted(Collections.reverseOrder()).collect(Collectors.toList())
分组
list.stream().collect(Collectors.groupingBy(DutyTurns::getOrderno))
根据id
Map<String,DutyClasses>classMap=classList.stream().collect(Collectors.toMap(DutyClasses::getUuid,DutyClasses->DutyClasses));
取集合一条数据
DutyLogdutyLog=dutyLogMapper.selectDutyLogList(null).stream().reduce((first,second)->second).get();
集合去重
inetAddresses.stream().map(InetAddress::getHostAddress).distinct().map(String::toLowerCase).collect(Collectors.toList());
kpiHandovers.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->newTreeSet<>(Comparator.comparing(KpiHandover::getDutyLogUuid))),ArrayList::new))
取平局值
list.stream().mapToDouble(TagValue::getValue).average().getAsDouble()
前5条数据
noticeService.selectNoticeList(notice).stream().limit(5l).collect(Collectors.toList());
筛选
historicProcessInstances=historicProcessInstances.stream().filter(historic->historic.getProcessDefinitionName().indexOf(flowTaskVo.getProcDefName())<0).collect(Collectors.toList());
集合
List<DictEntity> dictEntityList = dictService.findByType(6);
取出属性为集合
List<String> stateNameList = dictEntityList.stream().map(DictEntity::getName).collect(Collectors.toList());
取出属性为数组
Long[] ids = dictEntityList.stream().map(DictEntity::getId).toArray(Long[]::new);
集合去重
dictEntityList.stream().distinct().collect(Collectors.toList());