排序 降序
dataList.stream().sorted(Comparator.comparing(EventResponseEditData::getId)).collect(Collectors.toList());
dataList.sort((o1, o2) -> o2.getId().compareTo(o1.getId()));
去重
List<SourceTargetDto> treeSetClasData = allTableData.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(o -> o.getTargetName() + "#" + o.getDatabaseName() + "#" + o.getTableName() +"#"+ o.getChildId()))),
ArrayList::new));
分组
Map<String, List<UmpRedisEpEvent>> map = epEvents.stream().collect(Collectors.groupingBy(UmpRedisEpEvent::getHostIdPathRu));
取list中的对象的属性最大值
epEventsN = map.values().stream().map(events ->
events.stream().max(Comparator.comparing(UmpRedisEpEvent::getEventTime))).
filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
转换list类型
List<AccountAuthDeptVo> deptVoList = deptMapper.selectListVO(null);
List<OrgTerFileDataVO> epFileList = deptVoList.stream().map(deptVo -> {
OrgTerFileDataVO fileDataVO = new OrgTerFileDataVO();
BeanUtils.copyProperties(deptVo, fileDataVO);
return fileDataVO;
}).collect(Collectors.toList());
比较两个list取差集
List<TransferWarehouseO2ODetailDto> newTransfer = transferWarehouseO2ODetailDtoList.stream().filter(m -> !wlTransferWarehouseDList.stream().map(d -> d.getProviderPackId()).collect(Collectors.toList()).contains(m.getProviderPackId())).collect(Collectors.toList());
取两个集合交集
List<String> intersection = list1.stream().filter(item -> list2.contains(item)).collect(toList());
取两个集合差集
基础数据类型
List<String> reduceList = list1.stream().filter(item -> !list2.contains(item)).collect(toList());
自定义数据类型
List<FileLocal> intersection = fileLocalOne.stream().filter(userInfo ->
fileLocalTwo.stream().map(FileLocal::getId).collect(Collectors.toList()).contains(userInfo.getId())
).collect(Collectors.toList());
两个集合去重并集
List<String> list =new ArrayList<>(list1);
list.addAll(list2);
List<String> listAllDistinct = list.stream().distinct().collect(toList());