Search
 
SCRIPT & CODE EXAMPLE
 

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))
}
Comment

java stream distinct by object 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 does file exist 
Java :: how to iterate pixels image java 
Java :: how to check if a string is numeric 
Java :: containskey in java 
Java :: string reverse in java 
Java :: java get all directories in path 
Java :: java install in fedora 
Java :: isdigit java 
Java :: awk print second 
Java :: reentrantlock java 
Java :: implementing iterator for linked list java 
Java :: volley dependency 
Java :: add opacity to activity android 
Java :: validate date java 
Java :: str.substring last 2 java 
Java :: arrays in java 
Java :: how to check the end of a string java 
Java :: how to find location of java jdk 
Java :: declare array of chars java 
Java :: arrays.aslist 
Java :: java arraylist declaration 
Java :: java get relative path 
Java :: Java Read a Line of Text Using Scanner 
Java :: java math power 
Java :: java string not equal 
Java :: difference between object and class 
Java :: brew use java 11 
Java :: hello world program in java 
Java :: how to clear text fields in java 
Java :: importing all java libraries 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =