I have gone through related questions like How to ensure order of processing in java8 streams?, still ordering of output element is not completely clear to me. Therefore ple
As soon as you selected unordered
then the end result can come through in essentially a random order. Note though that there is no requirement that it do, so in fact it is likely you will still see some ordering in the output.
forEachOrdered
preserves the encounter order of the 'stream' so if you didn't have .unordered()
then it would ensure you see the elements in encounter order. If the stream is already unordered
though then it is pointless and you might as well use forEach
.
In other words forEachOrdered
preserves the encounter order in an already ordered stream. It does not do any sorting or other ordering though so if the stream is already unordered
then anything can happen.