Collectors: Aggregation Operations
In this lesson, we will learn about methods of the Collectors class, which are used for aggregation.
In this lesson, we will look at some of the methods of the Collectors
class that help us aggregate the data in streams, e.g., sum, average, etc.
1) counting()
This function returns a Collector
that counts the number of the input elements.
Suppose we have a list of employees, and we need the count of employees with an age more than 30.
In this case, we can use the counting()
method as shown below.
Get hands-on with 1200+ tech skills courses.