https://juejin.cn/post/7033005110716448776
list中的对象某个属性存在重复时将重复的对象去重
//根据skuAttrValueName值去重List<SkuValue> uniqueSkuValues = skuValues.stream().collect(
Collectors.collectingAndThen(Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(o -> o.getSkuAttrValueName()))), ArrayList::new)
);
java8获得对象集合中 某个属性的集合
List patientIdList = relationDOList.stream().map(RelationDO::getPatientId).collect(Collectors.toList());
收集成实体本身map ```java public Map
getIdAccountMap(List accounts) { return accounts.stream().collect(Collectors.toMap(Account::getId, account -> account)); }
public Map
4. bigdecimal求和计算
```java
BigDecimal openDyeAmount = CollUtil.def(sub == null ? null : sub.getDetails()).stream().filter(e -> e.getOpenDyeAmount() != null)
.map(DyeSubOrderDetailDTO::getOpenDyeAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
根据字段属性去重
List<DyeSubOrderDetailDTO> basFinishedGoodsColorList = CollUtil.def(sub == null ? CollUtil.emptyList() : sub.getDetails()).stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(DyeSubOrderDetailDTO::getBasFinishedGoodsColorId))), ArrayList::new));
分组
warehouseAllocationReceiveDetailDTOList.stream().collect(Collectors.groupingBy(WarehouseAllocationReceiveDetailDTO::getDyeOrderId));
6.排序
List<StudentInfo> studentsSortName = studentList.stream().sorted(Comparator.comparing(StudentInfo::getAge)).collect(Collectors.toList());