[HD-OCP17/21-Fundamentals Pg 779, Sec. 21.3.4 - quiz]

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

Moderator: admin

Post Reply
admin
Site Admin
Posts: 10383
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

[HD-OCP17/21-Fundamentals Pg 779, Sec. 21.3.4 - quiz]

Post by admin »

The answer A B C E is correct and the explanation is also correct. But the line "Hence, A is correct and C is incorrect." should be changed to "Hence, A and C are correct."

Veilok
Posts: 21
Joined: Sat Sep 01, 2018 10:53 am
Contact:

Re: [HD-OCP17/21-Fundamentals Pg 779, Sec. 21.3.4 - quiz]

Post by Veilok »

E should not be considered correct — we have a sequential stream, and findFirst() short-circuits, processing only the first element.

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

Re: [HD-OCP17/21-Fundamentals Pg 779, Sec. 21.3.4 - quiz]

Post by admin »

1. As the explanation notes, the stream is ordered, so no matter whether you insert a call to parallel() or sequential(), findFirst() will always return the first element (because it is the terminal operation).

2. The explanation also says, "The execution order of intermediate operations is not guaranteed even for ordered streams when the stream is parallel. " and map() is an intermediate operation and the given stream pipeline includes a call to parallel(), therefore, the map() operation will be executed in parallel and so Mapping 1 to Mapping 4 can be printed in any order.

Short circuiting behavior cannot guarantee that only 1 element will be processed if the stream is parallel because multiple threads are processing elements in parallel.

But if you change it to sequential() (instead of parallel()) then Mapping 1 to Mapping 4 will be printed in that order, which is what option E says. Therefore, E is a correct option.

Veilok
Posts: 21
Joined: Sat Sep 01, 2018 10:53 am
Contact:

Re: [HD-OCP17/21-Fundamentals Pg 779, Sec. 21.3.4 - quiz]

Post by Veilok »

However, only Mapping 1 will be printed, as elements 2, 3, and 4 are never mapped in a sequential stream with findFirst()

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

Re: [HD-OCP17/21-Fundamentals Pg 779, Sec. 21.3.4 - quiz]

Post by admin »

Duh...you are absolutely correct. Overlooked that point :oops:
Please tell me your name and you will be credited in the acknowledgements page of the book.

Veilok
Posts: 21
Joined: Sat Sep 01, 2018 10:53 am
Contact:

Re: [HD-OCP17/21-Fundamentals Pg 779, Sec. 21.3.4 - quiz]

Post by Veilok »

Thanks for the kind offer, but my name was already added to the acknowledgements page two months ago :cheers:

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 13 guests