Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java stream distinct by atribute

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

persons.stream().filter(distinctByKey(Person::getName))
Comment

PREVIOUS NEXT
Code Example
Java :: java thread dump 
Java :: keytool error: java.io.FileNotFoundException: c:UsersUSER_NAMEupload-keystore.jks (The system cannot find the path specified) 
Java :: on touch listener android 
Java :: how to get data from combobox in java 
Java :: overloading + operator in java 
Java :: java gridpane background color 
Java :: java create map 
Java :: java join two list 
Java :: check if string is uuid 
Java :: max heap java 
Java :: all possible valid IP addresses leetcode 
Java :: java.math.biginteger cannot be cast to java.lang.long 
Java :: springdoc 
Java :: string length in java 
Java :: assert throws exception java 
Java :: java break multiple loops 
Java :: random in java a to b 
Java :: uninstall java ac 
Java :: java for each loop 
Java :: set path in windows 
Java :: java call method from another class example 
Java :: 64 bit integer java 
Java :: spring maven plugin 
Java :: send data from service to activity class 
Java :: file append in java 
Java :: java files 
Java :: how to create localdate object in java 
Java :: execute exe java 
Java :: initialize a new class java 
Java :: java basic syntax 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =