About Question enthuware.ocpjp.v8.2.1869 :

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

Moderator: admin

Post Reply
javalass
Posts: 54
Joined: Thu Mar 03, 2016 1:26 pm
Contact:

About Question enthuware.ocpjp.v8.2.1869 :

Post by javalass »

If you had just this :
Optional<String> ops = names.stream().parallel().findAny();
It could potentially print any name from the list because of .parallel().
Technically, it could print an Optional containing any name from the list.

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

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

Post by admin »

Well, from that perspective it should say, it could potentially print an Optional containing a String containing chars for any name from the list :)
Since it is making a general statement about the code snippet whose last line is System.out.println(ops);, I think it is ok to say that it prints name. The fact that it prints an Optional is quite clear because we are indeed passing an Optional to println.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

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

Post by __JJ__ »

Hi Admin
If you had just this :

Code: Select all

Optional<String> ops = names.stream().parallel().findAny();
It could potentially print any name from the list because of .parallel().


My understanding is that it could potentially print any name from the list because of findAny. I.e. whether parallel is used or not, the behaviour is the same.

Thanks.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

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

Post by crazymind »

Just want to confirm one thing: we can't chain any terminal operation after another terminal operation, right? so, there is only one terminal operation is allowed in the stream.

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

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

Post by admin »

Yes and you should also understand the reason why.
If you like our products and services, please help us by posting your review here.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

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

Post by crazymind »

admin wrote:
Wed Feb 27, 2019 6:26 pm
Yes and you should also understand the reason why.
Cause terminal operations does not return stream?

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

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

Post by admin »

Correct.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 24 guests