Stream 中的成员方法
<R> R collect(Supplier<R> supplier,
BiConsumer<R, ? super T> accumulator,
BiConsumer<R, R> combiner)
以及对应各种基本类型流的成员方法(比如int的)
<R> R collect(Supplier<R> supplier,
ObjIntConsumer<R> accumulator,
BiConsumer<R, R> combiner)
其中 supplier 用于提供集合,比如以下两种方式均可用作 supplier;
ArrayList<T>::new;
()->list;// list 为事先声明的集合
accumulator 用于将把 Stream 中的对象加入到集合中(用例:List::add)
combiner 用于并行处理,只有 Stream 是允许并行的(调用parallel())才起作用
对于并行流,这个方法会把流的对象加入多个集合中,最后根据情况把这些集合中的对象添加到 supplier 所提供的集合中(用例:List::addAll)