I have a list of employees. They have isActive boolean field. I would like to divide employees into two lists: activeEmployees>
What is the most sophisticated way?
Java 12 of course with new Collectors::teeing
List> divided = employees.stream().collect(
Collectors.teeing(
Collectors.filtering(Employee::isActive, Collectors.toList()),
Collectors.filtering(Predicate.not(Employee::isActive), Collectors.toList()),
List::of
));
System.out.println(divided.get(0)); //active
System.out.println(divided.get(1)); //inactive