标签: java java-8 java-stream
我想知道,在使用Collectors.toSet方法创建的并行流上使用预定义的收集器(如Collectors.toList,collection.parallelStream())是否可以线程安全?
Collectors.toSet
Collectors.toList
collection.parallelStream()
或者必须使用自定义同步收集器,像这样?
collect(Collectors.toCollection(() -> Collections.synchronizedList(new ArrayList<>())))