一、Collector接口解读:
Collector接口解读:
1 public interface Collector<T, A, R> { 2 Supplier<A> supplier(); 3 BiConsumer<A, T> accumulator(); 4 BinaryOperator<A> combiner(); 5 Function<A, R> finisher(); 6 Set<Characteristics> characteristics(); 7 }
Collector<T, A, R>
T: stream中的元素类型;
A:累加器的类型,可以想象成一个容器。比如T要累加,转化为List<T>,A就是List类型。
R:最终返回值类型
T is the generic type of the items in the stream to be collected.
A is the type of the accumulator, the object on which the partial result will be accumulated during the collection process.
R is the type of the object(typically, but not always, the collection) resulting from the collect operation.
二、自定义Collector,看看是怎么实现的