Dyl*_*les 9 java collections java-8 java-stream
假设我有多个集合,我想将其作为单个流处理.最简单的方法是什么?是否有可以为我做这个的实用工具类,或者我必须自己滚动一些东西?
如果我的问题不明确,这基本上就是我想要做的:
Collection<Region> usaRegions;
Collection<Region> canadaRegions;
Collection<Region> mexicoRegions;
Stream<Region> northAmericanRegions = collect(usaRegions, canadaRegions, mexicoRegions);
public Stream<T> collect(T...) {
/* What goes here? */
}
Run Code Online (Sandbox Code Playgroud)
Bri*_*etz 13
或者,您可以使用flatMap:
Stream<Region> =
Stream.of(usaRegions, canadaRegions, mexicoRegions)
.flatMap(Collection::stream);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1923 次 |
| 最近记录: |