Collector解读以及自定义

一、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,看看是怎么实现的

猜你喜欢

转载自www.cnblogs.com/tenWood/p/11566742.html