Stream Collector
2015-06-15 12:12
281 查看
// Accumulate names into a List List<String> list = people.stream().map(Person::getName).collect(Collectors.toList()); // Accumulate names into a TreeSet Set<String> set = people.stream().map(Person::getName).collect(Collectors.toCollection(TreeSet::new)); // Convert elements to strings and concatenate them, separated by commas String joined = things.stream() .map(Object::toString) .collect(Collectors.joining(", ")); // Compute sum of salaries of employee int total = employees.stream() .collect(Collectors.summingInt(Employee::getSalary))); // Group employees by department Map<Department, List<Employee>> byDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment)); // Compute sum of salaries by department Map<Department, Integer> totalByDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment, Collectors.summingInt(Employee::getSalary))); // Partition students into passing and failing Map<Boolean, List<Student>> passingFailing = students.stream() .collect(Collectors.partitioningBy(s -> s.getGrade() >= PASS_THRESHOLD));
相关文章推荐
- 数据库查询之速度优化---游标定位
- 如何运营一个女性社区?
- win10开发已经接近终点 RTM正式版即将诞生
- read 详解
- opencv轮廓逼近的精度参数与周长cvContourPerimeter的汇总
- Tomcat中文乱码处理总结
- 跳槽解决四大难题,涨薪不用愁
- 女性社区TOP10
- 最大似然估计(Maximum likelihood estimation)
- PHP session回收机制(转)
- 对“专车”的正确引导即是对“互联网生态”的鼎力支持
- UIWebView与JS的交互
- javaweb基本组件之filter的使用
- riot.js学习【六】杂烩2
- 【原生js】js面向对象三大特征之继承笔记
- JAVA基础——properties存取
- 管理系统UI之五:响应UI可见性的变化(Responding to UI Visibility Changes)
- 用代码的方式创建教师表和学生表
- windows2012 powershell ise无法定位IIS问题解决
- 给在读研究生的一封信