public class CollectionUtils extends ObjectA utility class that provides re-usable functionality that relates to Java collections.
- Guus der Kinderen, firstname.lastname@example.org
Constructors Constructor Description
All Methods Static Methods Concrete Methods Modifier and Type Method Description
static <T> Predicate<T>
distinctByKey(Function<? super T,Object> keyExtractor)Returns a stateful stream filter that, once applied to a stream, returns a stream consisting of the distinct elements (according to the specified key).
distinctByKeyReturns a stateful stream filter that, once applied to a stream, returns a stream consisting of the distinct elements (according to the specified key).
The implementation of
Stream.distinct()can be used to return a stream that has distinct elements, based on the implementation of
Object.equals(Object). That implementation does not allow to filter a stream based on one property of each object. The implementation of provided by this method does.
- Type Parameters:
T- Stream element type.
keyExtractor- A function to extract the desired key from the stream objects (cannot be null).
- A filter
- See Also:
- Stack Overflow: Java Lambda Stream Distinct() on arbitrary key?