Flattening a collection

前端 未结 9 2044
走了就别回头了
走了就别回头了 2020-11-30 02:55

Say I have a Map>

I can get the values of the map easily enough, and iterate over it to produce a single

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 03:14

    When searching for "java 8 flatten" this is the only mentioning. And it's not about flattening stream either. So for great good I just leave it here

    .flatMap(Collection::stream)
    

    I'm also surprised no one has given concurrent java 8 answer to original question which is

    .collect(ArrayList::new, ArrayList::addAll, ArrayList::addAll);
    

提交回复
热议问题