// java.util.stream.Collectors 类的主要作用就是辅助进行各类有用的 reduction 操作,例如转变输出为 Collection,把 Stream 元素进行归组。

public final class Collectors
extends Object
Implementations of Collector that implement various useful reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria, etc.
The following are examples of using the predefined collectors to perform common mutable reduction tasks: // 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));

最新文章

  1. mysql 命令行还原备份数据库
  2. SharePoint Framework 开发工具和库
  3. Eclipse 一直提示 loading descriptor for 的解决方法(转)
  4. [开源应用]利用HTTPHandler+resumableJs+HTML5实现拖拽上传[大]文件
  5. 去除移动端 a标签 点击有一个 阴影效果
  6. C#中泛型容器Stack&lt;T&gt;
  7. Cocoapods 64-bit(iPhone5s) 问题解决方案
  8. HTTP真的很简单(转)
  9. ios逆向过程中lldb调试技巧
  10. 深入理解Java:内省(Introspector)
  11. python常用的基本操作
  12. PostgreSQL 在Ubuntu下如何修改postgres默认密码
  13. Java集合之LinkedList源码分析
  14. Alpha冲刺! Day6 - 砍柴
  15. Python3-RabbitMQ 3.7.2学习——Hello World(二)
  16. linux manjaro 配置 pytorch gpu 环境
  17. bat删除过期文件(FORFILES)
  18. what&#39;s the python之函数及装饰器
  19. G 面经 &amp;&amp; Leetcode: Longest Repeating Character Replacement
  20. nohup php -f xx.php &amp;

热门文章

  1. SMARTY核心
  2. 用C#做成的程序如何打包部署,在其他PC机运行
  3. RedHat Enterprise7 搭建ISCSI
  4. 你应该知道的 MySQL 的锁
  5. SrpingMVC通过JSON注入from数据到实体自定义(LocalDateTime,LocalDate,Boolean类型)字段的序列化、反序列化方法
  6. Spring MVC的多视图解析器配置及与Freemarker的集成
  7. 后缀数组--summer-work之我连模板题都做不起
  8. koa2数据请求相关问题解决方案汇总
  9. UE4 RHI(2)
  10. bug解决思路——插入数据时,前台不展示数据