Page 1 of 1

About Question enthuware.ocpjp.v8.2.1853 :

Posted: Wed May 17, 2017 9:21 am
by lenalena
I have a question about forEachOrdered.

The javadoc states that forEachOrdered
Performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined encounter order.
I'm a bit confused by the bold part. If you take a parallel stream and then call forEachOrdered on it - does it mean that the "defined encounter order" will be the same order in which the elements were inserted into the stream, so in effect stream.parallel().forEachOrdered() reassembles the parallel stream into it's original order?

Re: About Question enthuware.ocpjp.v8.2.1853 :

Posted: Wed May 17, 2017 10:36 pm
by admin
Yes, for example, if you create a stream using an array, then the order is the order of elements in that array. This order will be preserved even if you use parallel stream.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1853 :

Posted: Wed Oct 23, 2019 2:51 pm
by dongyingname
I ran the code and it definitely compiled. But I still don't understand why

Code: Select all

.peek(item->{destination.add(item); })
makes sense here.
the variable destination is not effectively final isn't it?

Re: About Question enthuware.ocpjp.v8.2.1853 :

Posted: Wed Oct 23, 2019 9:06 pm
by admin
Why do you think destination is not effectively final. It is not being changed anywhere in the code.