I was watching a presentation on Java, and at one point, the lecturer said:
\"Mutability is OK, sharing is nice, shared mutability is devil\'s work.\"
In the first example, if you were to use parallel(), you’d have no guarantee of the insertions (multiple threads inserting the same element for example).
collect(...) on the other hand, when run in parallel, splits the work and internally collects the results in an intermediate step and then adds them to the final list, ensuring order and safety.