- partitionBy operation on Collectors provides a way to aggregate the result of a stream operation into a map.
- The map contains two items which are the result partitions based on a predicate function.
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
Map<Boolean, List<Employee>> employeePartitions = employees
.collect(Collectors.partitioningBy(employee -> employee.getSalary() > 50));
Comments
Post a comment