【发布时间】:2015-10-20 19:16:13
【问题描述】:
所以我有一个Stream<Collection<Long>>,我是通过对另一个流进行一系列转换获得的。
我需要做的是将Stream<Collection<Long>> 合并为一个Collection<Long>。
我可以将它们全部收集到这样的列表中:
<Stream<Collection<Long>> streamOfCollections = /* get the stream */;
List<Collection<Long>> listOfCollections = streamOfCollections.collect(Collectors.toList());
然后我可以遍历该集合列表以将它们合并为一个。
但是,我想一定有一种简单的方法可以使用.map() 或.collect() 将集合流组合成一个Collection<Long>。我只是想不出该怎么做。有什么想法吗?
【问题讨论】:
-
查看
flatMap。
标签: java collections java-8 java-stream