【发布时间】:2021-11-18 22:18:37
【问题描述】:
我有一个 Employee 类,其中包含薪水和部门以及员工列表。
static class Employee {
private String department;
private int salary;
//getters
getDeparment()
getSalary()
}
List<Employee>
我需要找到至少有 30 名员工的部门数量,他们支付了最低 100 的工资。
到目前为止,我得到了每个部门的员工人数。但我不确定如何应用过滤器。
HashMap<String, Long> collect = employees
.stream()
.collect(Collectors.groupingBy(Employee::getDepartment, HashMap::new, Collectors.counting()));
任何帮助将不胜感激。
【问题讨论】:
-
我想下一步是做一个类似的语句来收集每个部门的最低工资。然后尝试将两者结合在一起。
-
至于应用过滤器,您应该可以将
.stream().filter()添加到您目前所拥有的内容中。
标签: java java-stream