首页 > 其他 > 详细

"collect" method

时间:2017-05-21 14:22:22      阅读:306      评论:0      收藏:0      [点我收藏+]

1.The collect is declared by the Interface of Stream.The param is Collector Interface.

<R, A> R collect(Collector<? super T, A, R> collector);

 

2.The Collector Interface mainly contains 4 functions about:

  (1)creation of a new result container ({@link #supplier()})

  (2)incorporating a new data element into a result container ({@link #accumulator()})

  (3)combining two result containers into one ({@link #combiner()})

  (4)performing an optional final transform on the container ({@link #finisher()}

3.The Collectors Class has a inner class which implements above Collector.So you can invoke collect by this assistant class (Collectors).The Collectors class implement some common operations.

  ex:

public static <T>
    Collector<T, ?, List<T>> toList() {
        return new CollectorImpl<>((Supplier<List<T>>) ArrayList::new, List::add,
                                   (left, right) -> { left.addAll(right); return left; },
                                   CH_ID);
    }

 

  

  

"collect" method

原文:http://www.cnblogs.com/huiGod/p/6880642.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!