一个ArrayList,里面保存了若干个雇员对象的实例,雇员对象包含姓名,部门,薪酬等属性。现在要依据这个ArrayList统计出薪酬大于M,人数大于N的部门有多少个,要求不能使用循环,请问这个怎么实现?
全部评论
我不信filter里没用循环
点赞 回复 分享
发布于 2021-05-02 21:56
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();
点赞 回复 分享
发布于 2021-04-15 14:12

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务