- summing operation on Collectors provides a way to aggregate the result of a stream operation into a number.
- The different implementations yield Integer, Double and Long which are summingInt, summingDouble, summingLong respectively.
stream of employees
Stream employees = Stream.of(
new Employee("Joe", "Blogs", "Sales", 100.0),
new Employee("Richardo", "Banks", "Engineering", 50.0),
new Employee("Hewlet", "Packer", "Warehouse", 40.0)
);
USAGE
collecting stream transformation result in a Double
collecting stream transformation result in a Double
Double summedSalaries = employees
.filter(employee -> employee.getLastName().startsWith("B"))
.collect(Collectors.summingDouble(Employee::getSalary));
Comments
Post a comment