The following code is not putting all the elements in the destination list after finishing parallel process. Is there any reason for this?
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());
}
Output: Source Size:10000 destination size:4343