![](/img/trans.png)
[英]What's the easiest and most efficient way to combine UDP and RPCs in java?
[英]What's the easiest way to combine multiple collections into a stream in Java?
假設我有多個集合,我想將其作為單個流處理。 最簡單的方法是什么? 是否有可以為我做這個的實用工具類,或者我必須自己滾動一些東西?
如果我的問題不明確,這基本上就是我想要做的:
Collection<Region> usaRegions;
Collection<Region> canadaRegions;
Collection<Region> mexicoRegions;
Stream<Region> northAmericanRegions = collect(usaRegions, canadaRegions, mexicoRegions);
public Stream<T> collect(T...) {
/* What goes here? */
}
或者,您可以使用flatMap:
Stream<Region> =
Stream.of(usaRegions, canadaRegions, mexicoRegions)
.flatMap(Collection::stream);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.