In the streaming library included with Java 8, we're provided with the forEachOrdered API whose documentation is reproduced here
void forEachOrdered(Consumer action)
Performs an action for each element of this stream.
This is a terminal operation.
This operation processes the elements one at a time, in encounter order if one exists. Performing the action for one element happens-before performing the action for subsequent elements, but for any given element, the action may be performed in whatever thread the library chooses.
Do we have any guarantees in terms of ordering from the map API?
For example, I have the following in code
private final BazUtils bazUtils;
public List<Foo> getFoos(List<Bar> bars) {
AtomicInteger idx = new AtomicInteger(1);
return bars.stream()
.map(bar -> bazUtils.getFoo(bar, idx.getAndAdd(1)))
.collect(Collectors.toList());
}
Will the order of bars
be respected in processing?