Skip to content

Tag Archives: Java-Collectors

Collectors is one of the utility class in JDK which contains a lot of utility functions. It is mostly used with Stream API as a… Read More
Introduced in Java 8, the Stream API is used to process collections of objects. A stream is a sequence of objects that supports various methods… Read More
Given a stream containing some elements, the task is to find the duplicate elements in this stream in Java. Examples: Input: Stream = {5, 13,… Read More
The groupingBy() method of Collectors class in Java are used for grouping objects by some property and storing results in a Map instance. In order… Read More
The collectingAndThen(Collector downstream, Function finisher) method of class collectors in Java, which adopts Collector so that we can perform an additional finishing transformation. Syntax :… Read More
The toMap() method is a static method of Collectors class which returns a Collector that accumulates elements into a Map whose keys and values are… Read More
Collectors partitioningBy() method is a predefined method of java.util.stream.Collectors class which is used to partition a stream of objects(or a set of elements) based on… Read More
The toList() method of Collectors Class is a static (class) method. It returns a Collector Interface that gathers the input data onto a new list.… Read More
Collectors toCollection(Supplier<C> collectionFactory) method in Java is used to create a Collection using Collector. It returns a Collector that accumulates the input elements into a… Read More
Collectors toSet() returns a Collector that accumulates the input elements into a new Set. There are no guarantees on the type, mutability, serializability, or thread-safety… Read More
Collectors maxBy(Comparator<? super T> comparator) is used to find an element according to the comparator passed as the parameter. It returns a Collector that produces… Read More
Collectors minBy(Comparator<? super T> comparator) is used to find an element according to the comparator passed as the parameter. It returns a Collector that produces… Read More
Collectors averagingDouble(ToDoubleFunction<? super T> mapper) method is used to find the mean of the double values passed in the parameters. This method returns a Collector… Read More
Collectors averagingLong(ToLongFunction<? super T> mapper) method is used to find the mean of the long values passed in the parameters. This method returns a Collector… Read More
Collectors counting() method is used to count the number of elements passed in the stream as the parameter. It returns a Collector accepting elements of… Read More