码迷,mamicode.com
首页 > 其他好文 > 详细

"collect" method

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

标签:static   span   .so   nal   min   rpo   ora   combiner   ram   

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

标签:static   span   .so   nal   min   rpo   ora   combiner   ram   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!