티스토리 뷰

공부

[Java] distinct by property

승가비 2020. 10. 28. 01:08
728x90
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
    Set<Object> seen = ConcurrentHashMap.newKeySet();
    return t -> seen.add(keyExtractor.apply(t));
}

https://stackoverflow.com/questions/23699371/java-8-distinct-by-property

 

Java 8 Distinct by property

In Java 8 how can I filter a collection using the Stream API by checking the distinctness of a property of each object? For example I have a list of Person object and I want to remove people with ...

stackoverflow.com

 

728x90

'공부' 카테고리의 다른 글

[Java] random shuffle list  (0) 2020.10.28
[JS] date deep copy  (0) 2020.10.28
[JS] get yesterday  (0) 2020.10.28
[Java] getHour()  (0) 2020.10.28
[Presto] extract value from a column JSON  (0) 2020.10.28
댓글