About Question enthuware.ocpjp.v8.2.1853 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

About Question enthuware.ocpjp.v8.2.1853 :

Post 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?

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

dongyingname
Posts: 18
Joined: Sat Jun 22, 2019 4:10 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Why do you think destination is not effectively final. It is not being changed anywhere in the code.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 112 guests