Why can I collect a parallel stream to an arbitrarily large array but not a sequential stream? : <p>From answering <a href="https://stackoverflow.com/q/49760006/7294647">this question</a>, 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):</p>

<pre><code>Integer[] newArray = Stream.of(7, 8)
                           .parallel()
                           .toArray(i -&gt; new Integer[] {1, 2, 3, 4, 5, 6});

System.out.println(Arrays.toString(newArray));
</code></pre>

<p>Output:</p>

<pre><code>[7, 8, 3, 4, 5, 6]
</code></pre>

<p>However, attempting this with a sequential stream throws an <code>IllegalStateException</code>:</p>

<pre><code>Integer[] newArray = Stream.of(7, 8)
                           .toArray(i -&gt; new Integer[] {1, 2, 3, 4, 5, 6});

System.out.println(Arrays.toString(newArray));
</code></pre>

<p>Output:</p>

<pre><code>Exception in thread "main" java.lang.IllegalStateException: Begin size 2 is not equal to fixed size 6
    at java.base/java.util.stream.Nodes$FixedNodeBuilder.begin(Nodes.java:1222)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:483)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:550)
    at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
    at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:517)
    at test/test.Test.main(Test.java:30)
</code></pre>

<p>I'm curious as to why the sequential stream does not overwrite elements of the array as the parallel stream does.  I searched around a bit and was not able to find documentation regarding this, but I assume it exists somewhere.</p>
