Collectors
Class Collectors
- Collectors is a final class that extends the Object class.
- 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 final step.
- Functions associated with Collectors usually get used inside collect() methods.
- Collectors class is part of Stream package and can be imported as:
import static java.util.stream.Collectors.*;
//java.lang.Object
// ↳ java.util.stream
// ↳ class Collectors
Running Examples
🗃️ groupingBy
3 items
📄️ joining
joining()
📄️ partitioningBy
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 a given predicate. There are two overloaded variants of the method that are present. One takes only a predicate as a parameter whereas the other takes both predicate and a collector instance as parameters.
📄️ reducing
The overloaded static methods, Collectors.**reducing()** return a Collector which perform a reduction on the input stream elements according to the provided binary operator.
📄️ summarizing
**summarizingDouble()**
📄️ summing
**summingDouble()**