Can a Stream be sequentially processed for part of the pipeline, and then as parallel?

Viewed 722

I have the following code which does not work as I intended (a random line, instead of the first, is skipped):

Files.lines(path)
     .skip(1)
     .parallel()
     .forEach( System.out::println )

I have a feeling I misunderstood the behavior of Streams. The question is: Can I first treat a stream as sequential (and use "stateful intermediate operations") and then feed it into a parallel forEach?

4 Answers
Related