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 :: SpEL define default 
Java :: how to delete last char in string java 
Java :: how to clear a text file in java 
Java :: java GUI jframe text 
Java :: take a value from keyboard java 
Java :: javafx button with icon 
Java :: java jcombobox itemlistener only if value changed 
Java :: como utilizar random en java 
Java :: cannot lock java compile cache as it has already been locked by this process 
Java :: java double buffering jpanel 
Java :: find difference in days between two dates java 
Java :: java elapsedTime 
Java :: fullscreen java jframe 
Java :: populate arraylist java one line 
Java :: -Xlint:deprecation 
Java :: bundletool aab to apk 
Java :: jakkala siva venkata deepesh 
Java :: how to make background image transparent in android studio 
Java :: events that people think are unlikely but actually have high probability 
Java :: android java format date time 
Java :: regex validation for special characters in java 
Java :: how to set audio of a java sound clip 
Java :: count the number of words in a string java 
Java :: how to print arraylist 
Java :: rates api 
Java :: decimals java 
Java :: list to observablelistz 
Java :: check if object in array java 
Java :: javafx change text size 
Java :: java swing enter key press event 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =