Stream流的收集操作
- 收集Stream流的含义:就是把Stream流操作后的结果数据 转回 到 集合 或者 数组 中去。
- Stream流:方便操作 集合 / 数组 的 手段。
- 集合 / 数组:才是开发中的 目的 。
Stream流的收集方法
- R collect(Collector collector)
- 开始收集Stream流,指定收集器
Collectors工具类提供了具体的收集方式
- public static<T> Collector toList()
- 把元素收集到List集合中
- public static<T> Collector toSet()
- 把元素收集到Set集合中
- public static Collector toMap(Function keyMapper,Function valueMapper)
- 把元素收集到Map集合中