以下代码在完成并行处理后并未将所有元素放入目标列表中。这有什么原因吗?
public static void main(String[] args) {
List<Integer> source =new ArrayList<>();
List<Integer> destination = new ArrayList<>();
IntStream.range(0, 10000).forEach(element ->{
source.add(element);
});
//System.out.println(source.size());
source.parallelStream().forEach(c->{
destination.add(c);
});
System.out.println("Source Size:"+source.size());
System.out.println("destination size:"+destination.size());
}
Run Code Online (Sandbox Code Playgroud)
输出:源大小:10000 目标大小:4343