In Java 8 how can I filter a collection using the Stream API by checking the distinctness of a property of each object?
Stream
For example I have a list of
There's a simpler approach using a TreeSet with a custom comparator.
persons.stream() .collect(Collectors.toCollection( () -> new TreeSet((p1, p2) -> p1.getName().compareTo(p2.getName())) ));