About Question enthuware.ocpjp.ii.v11.2.1853 :
Posted: Sat Jan 09, 2021 3:43 am
Hi,
Is ordered guaranteed for foreach operation? According to doc:
Is ordered guaranteed for foreach operation? According to doc:
So I understand that line //4 shall also be replaced with forEachOrdered ?void forEach(Consumer<? super T> action)
Performs an action for each element of this stream.
This is a terminal operation.
The behavior of this operation is explicitly nondeterministic. For parallel stream pipelines, this operation does not guarantee to respect the encounter order of the stream, as doing so would sacrifice the benefit of parallelism. For any given element, the action may be performed at whatever time and in whatever thread the library chooses. If the action accesses shared state, it is responsible for providing the required synchronization.
Parameters: