Java 8 - Creating a Custom Collector for Streams

1 · Kumar Rohit · May 23, 2019, midnight
Java Streams provide a wide range of collectors which is generally sufficient for most of the day to day use. But sometimes you need to perform some special operations, which is not provided out of the box. We can create our own custom collectors to suit our requirement. We have a requirement, we want to collect only distinct items from a list. Create Custom Collector If we look the at the Collector interface, it provided 5 methods which we need to implement. public interface Collector<T, A, R> ...