(1) 两个集合遍历满足条件返回 否则返回空
list.stream().map(m -> emrList.stream().filter(se -> Objects.equals(m.getUserEmrId(),se.getId()))
.findFirst().map(ma ->{
m.setAge(ma.getAge());
m.setName(ma.getName());
m.setPhoneNum(ma.getPhoneNum());
m.setSex(ma.getSex());
return m;
}).orElse(null)).collect(Collectors.toList());
(2) 集合提取名义字段并且转为Long类型后 返回List
List<Long> list = esPageVO.getList().stream().map(UserEmrEsVO::getId).map(x -> x.longValue()).collect(Collectors.toList());
(3) 筛选list中没有的数据
List filterList = addList.stream().filter(i -> !dataList.contains(i)).toList();
(4) 将不包含逗号的字典code筛选出来,因为带逗号的是表字典,而不是普通的数据字典
List<String> filterDictCodes = dictCodeList.stream().filter(key -> !key.contains(",")).collect(Collectors.toList());
(5) 集合中提取某一字段
List<Long> spuId = gorySpuDTOS.stream().map(CategorySpuDTO::getSpuId).collect(Collectors.toList());
(6) 集合中筛选ID不为空的数据
list.stream().map(m ->{ if(Objects.nonNull(m.getSpuId())){ lists.add(m);
}return m;}).collect(Collectors.toList());
(7) 为集合中某一字段添加数据
getUserEmrDetail().stream().map(m -> { m.setUserEmrId(userEmr.getId());m.setCreateTime(LocalDateTime.now());return m;}).collect(Collectors.toList());
(8) 循环
getUserEmrImg().stream().forEach(m -> iUserEmrImgService.upUserEmrImg(m));
(9) List 转map
Map<Long,Long> sumData = itemVOS.stream().collect(Collectors.toMap(OrderItemVO::getUserId,OrderItemVO::getSpuTotalAmount,(value1, value2) -> value1));
Map<String, Set<ShopVo>> collect = lastList.stream().collect(Collectors.groupingBy(m->m.getPhone()+","+m.getName(),Collectors.toSet()));
// 取map值
if(CollectionUtil.isNotEmpty(sumData)&&sumData.containsKey(shopVo.getUserId())){}
(10)根据条件修改集合内容 并返回自身修改后的结果
inws.stream().map(m ->{
boolean exist = Objects.equals(settingDetailVOS.get(0).getPhoneNum(),m.getPhone());
if(exist) {
m.setPree(m.getPree() + duoyu);
}
return m;
}).collect(Collectors.toList());