Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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))
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #stream #distinct #property
ADD COMMENT
Topic
Name
3+3 =