1 List list = new ArrayList<>();
2 List listByName = list.stream().filter(distinctByName(item -> item.getName())).collect(Collectors.toList());
3 private static <T> Predicate<T> distinctByName(Function<? super T , Object> keyExtractor) {
4 Map<Object , Boolean> seen = new ConcurrentHaskMap<>();
5 return t -> seen.putIfAbsent(keyExtractor.apply(t)) , Boolean.True) == null;
6
7 }
JDK1.8stream根据对象的某一字段去重
点赞
收藏