字符串去重
List<String> dataList = list.stream().distinct().collect(Collectors.toList());
对象属性去重
List<UserParam> result = userList.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(UserParam::getOrgCode))), ArrayList::new));
对象属性去重
根据字段 getLabelsName 去重
List<Object> collect = labelsListDtoPageInfo.stream().filter(distinctByKey(LabelsListDto::getLabelsName)).collect(Collectors.toList());
//distinctByKey自己定义
public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}