Here you can find the source of sequence(List
public static <T> CompletableFuture<List<T>> sequence(List<CompletableFuture<T>> futures)
//package com.java2s; //License from project: Apache License import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; public class Main { public static <T> CompletableFuture<List<T>> sequence(List<CompletableFuture<T>> futures) { /*/*from www . j av a2 s . c om*/ CompletableFuture<Void> allDoneFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])); return allDoneFuture.thenApply(v -> futures.stream(). map(future -> future.join()). collect(Collectors.<T>toList()) ); */ return CompletableFuture .supplyAsync(() -> futures.stream().map(future -> future.join()).collect(Collectors.<T>toList())); } }