应用场景:在开发中过程中 会存在根据List集合中的对象一个或者多个元素进行去重
1:根据List集合中的对象一个元素进行去重
List<PurchaseHead> organizationPurchaseHeadList = purchaseHeadList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
Comparator.comparing(PurchaseHead::getOrganizationId)
)), ArrayList::new));
2:根据List集合中的对象多个元素进行去重
List<StorageLotTypeLockNum> storageLotLockNumList = lotTypeLockNumList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getGoodsId() + ";" + o.getLotNumber())
)), ArrayList::new));
3:List<String>去重
goodsIdList = goodsIdList.stream().distinct().collect(Collectors.toList());