lambdaconcurrentList<Map>toMap

编程

Object c = Stream.of(

CompletableFuture.supplyAsync(() -> {

Map m = new HashMap();

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

e.printStackTrace();

}

System.out.println("a order");

m.put("a1", "a1");

m.put("a2", "a2");

return m;

}),

CompletableFuture.supplyAsync(() -> {

Map m = new HashMap();

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

e.printStackTrace();

}

m.put("b1", "b1");

m.put("b2", "b2");

System.out.println("b order ");

return m;

}))

.parallel()

.flatMap(v -> ((Set<Map.Entry>) Optional.of(v.join()).orElse(new HashMap()).entrySet()).stream())

.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (k1, k2) -> k1 == null ? k2 : k1));

System.out.println(c);

以上是 lambdaconcurrentList&lt;Map&gt;toMap 的全部内容, 来源链接: utcz.com/z/511927.html

回到顶部