Why can I collect a parallel stream to an arbitrarily large array but not a sequential stream?
问题 From answering this question, I ran into a peculiar feature. The following code works as I assumed it would (the first two values within the existing array would be overridden): Integer[] newArray = Stream.of(7, 8) .parallel() .toArray(i -> new Integer[] {1, 2, 3, 4, 5, 6}); System.out.println(Arrays.toString(newArray)); Output: [7, 8, 3, 4, 5, 6] However, attempting this with a sequential stream throws an IllegalStateException : Integer[] newArray = Stream.of(7, 8) .toArray(i -> new Integer[