List<Book> list = new ArrayList<>(); list.add(new Book("apple")); list.add(new Book("apple")); list.add(new Book("pear")); list.add(new Book("melon")); List<Book> assetBasicInfoEntityList = list.stream() .filter(distinctByKey(Book::getName)) .collect(Collectors.toList());
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { Set<Object> seen = ConcurrentHashMap.newKeySet(); return t -> seen.add(keyExtractor.apply(t)); }
标签:distinctByKey,apple,Stream,过滤,list,add,Book,某个,new From: https://www.cnblogs.com/juniorMa/p/16857894.html