Answers for "stream distinct by property"

1

stream distinct by property

public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
    Set<Object> seen = ConcurrentHashMap.newKeySet();
    return t -> seen.add(keyExtractor.apply(t));
}

public void distunctPersons () {
	persons.stream().filter(distinctByKey(Person::getName))
}
Posted by: Guest on April-26-2022

Code answers related to "stream distinct by property"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language