how to force Java 8 streams to execute sequentially?

Viewed 1025

I have a Stream as a method's argument. I don't know if it parallel or not. How can I guarantee sequential execute it?

(no if/else/instance of pls)

Thanks

1 Answers

wait... just invoke sequential() on it?

This is just a flag so the last invocation of sequential/parallel wins, that means even if your stream is parallel and you receive it as a method argument, just invoke sequential anywhere before the terminal operation and you are done

Related