Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java list distinct by object attribute

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

get distinct values from list of objects java

public Set<String> areas(final List<Employee> employees) {
    Set<String> areas = new HashSet<>();
    for(final Employee employee: employees) {
        areas.add(employee.getArea());
    }
    return areas;
}
Comment

PREVIOUS NEXT
Code Example
Java :: play mp3 android java 
Java :: frequency of each element from list in java 
Java :: days between two dates android 
Java :: how to get input form combobox java 
Java :: printing arraylist 
Java :: print float number with only four places after the decimal point in java 
Java :: java srting array to string 
Java :: arraylist items into string 
Java :: java remote debug 
Java :: java get bigger int 
Java :: java add to map 
Java :: concat result of List to one text java 
Java :: java csv line split 
Java :: java while loop example 
Java :: how to assert that an exception is thrown java 
Java :: array java 
Java :: hello world java code 
Java :: c# or java 
Java :: how to add element to end of array java 
Java :: array sort java 
Java :: java convert array to list 
Java :: enum set in java 
Java :: android-edittext allow only characters and numbers 
Java :: java localtime 
Java :: java read file 
Java :: bean factory vs application context 
Java :: find minimum number in java 
Java :: android studio change button color programmatically 
Java :: display in java 
Java :: java is list ordered 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =