我有一个employees的列表。他们有isActive布尔字段。我想把employees分成两个列表:activeEmployees和formerEmployees。是否可以使用Stream?最复杂的方法是什么?
发布于 2019-04-03 11:06:31
最复杂的方法是什么?
Java12当然有新的Collectors::teeing
List<List<Employee>> 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));  //inactivehttps://stackoverflow.com/questions/46958023
复制相似问题