There is no guarantee of the order in which list items are passed to predicate lambdas. Stream documentation makes guarantees regarding the output of streams, including the order of encounter; it does not make guarantees about implementation details, such as the order in which filter predicates are applied.
Therefore, the documentation does not prevent filter
from, say, reading several elements, running the predicate on them in reverse order, and then sending the elements passing the predicate to the output of the stream in the order in which they came in. I don't know why filter()
would do something like that, but doing so wouldn't break any guarantee made in the documentation.
You can make pretty strong inference from the documentation that filter()
would call predicate on the elements in the order in which collection supplies them, because you are passing the result of calling stream()
on a list, which calls Collection.stream()
, and, according to Java documentation, guarantees that Stream<T>
produced in this way is sequential:
Returns a sequential Stream
with this collection as its source.
Further, filter()
is stateless:
Stateless operations, such as filter
and map
, retain no state from previously seen element when processing a new element - each element can be processed independently of operations on other elements.
Therefore it is rather likely that filter
would call the predicate on elements in the order they are supplied by the collection.
I am talking here specifically about stream()
, not parallelStream()
Note that Stream<T>
may be unordered without being parallel. For example, calling unordered()
on a stream()
, the result becomes unordered, but not parallel.