Java 8 parallelstream collect return list into one list instead of list of list

Java 8 parallelstream collect return list into one single list instead of list of list

我想将并行流中的列表结果收集到一个列表中。让我们看看这段代码来更好地解释我的问题。这是我得到的:

List<Object> a = new ArrayList<>();

List<List<Object>> result a.parallelStream() // I get a List of List
   .map(a -> { return new ArrayList(); })
   .collect(Collectors.toList());

但我真正想要拥有的更多是这样的:

List<Object> a = new ArrayList<>();

List<Object> result a.parallelStream()   // I want to add all list elements into one List of objects
   .map(a -> { return new ArrayList(); })
   .collect(Collectors.???); 

flatMap 可以将内部列表的元素折叠成一个列表:

List<List<Object>> a = ...
List<Object> result = a.stream()
                       .flatMap (l -> l.stream())
                       .collect(Collectors.toList());