Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force Java 8 streams to execute sequentially?

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

like image 559
arminvanbuuren Avatar asked Mar 27 '26 17:03

arminvanbuuren


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

like image 120
Eugene Avatar answered Mar 30 '26 07:03

Eugene



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!