一个ArrayList,里面保存了若干个雇员对象的实例,雇员对象包含姓名,部门,薪酬等属性。现在要依据这个ArrayList统计出薪酬大于M,人数大于N的部门有多少个,要求不能使用循环,请问这个怎么实现?
全部评论
我不信filter里没用循环
double salaryThreshold = 1000;
long nums = 2;
long result = employeeList.stream()
.filter(employee -> employee.getSalary() > salaryThreshold)
.collect(Collectors.groupingBy(Employee::getDepartment, Collectors.counting()))
.values().stream()
.filter(aLong -> aLong > nums)
.count();
相关推荐
点赞 评论 收藏
分享
