【发布时间】:2020-04-21 17:05:12
【问题描述】:
我有 List 和 Employees 的加入日期不同。我想在特定日期之前和之后使用流从列表中获取员工。
我尝试了以下代码,
List<Employee> employeeListAfter = employeeList.stream()
.filter(e -> e.joiningDate.isAfter(specificDate))
.collect(Collectors.toList());
List<Employee> employeeListBefore = employeeList.stream()
.filter(e -> e.joiningDate.isBefore(specificDate))
.collect(Collectors.toList());
class Employee{
int id;
String name;
LocalDate joiningDate;
}
有没有办法在单流中做到这一点?
【问题讨论】:
-
你可以使用
partitioningBy -
之前和之后 - 所以您想要除当天加入的员工之外的所有员工?
-
假设它是“至少从那时起就成为员工”,你会想分成之前而不是之前,根本不关心之后。
标签: java dictionary collections java-8 java-stream