How is the first element determined when findFirst
operation is used in a parallel stream?
EDIT
@nullpointer: My intent of question is different from what you have posted as possible duplicate(wherein, the element is doing a job so, there are lot many factors come into play) link and your second link(question) does not talk about parallelism.
ALL: Clarifying on original question, which I admit, should have provided more information - Given an
ArrayList
of strings(say of a million words as elements) and try to find first element usingfindFirst
, how is first element(say the lookup word be "HelloWorld") determined on parallel(Stream.parallelStream()
) execution? I raise this question because as the list is ordered(in which case first encounter in order is returned usingfindFirst
), is parallel execution even considered at first place? If so, the look up word could be anywhere in and any number of instances in a million words/elements and as the list could be divided into many parallel sub-tasks, in this case how is the first element determined?