Flattening a collection

前端 未结 9 2048
走了就别回头了
走了就别回头了 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 03:37

    Suggested by a colleague:

    listOfLists.stream().flatMap(e -> e.stream()).collect(Lists.toList())
    

    I like it better than forEach().

提交回复
热议问题