I'm preparing for OCP and have some question that really don't understand with parallel streams. Here is my code:
public class Test {
static long n = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.parallelStream()
.map(i -> "" + i)
.peek(System.out::print)
.count();
public static void main(String... args) {
System.out.println(n);
}
}
When I run that program it can print some numbers and simply hang out without termination. Can somebody explain what is going on under the hood and what is the cause of waiting?