Page 1 of 1
About Question enthuware.ocpjp.v8.2.1869 :
Posted: Thu Mar 10, 2016 10:19 am
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.
Re: About Question enthuware.ocpjp.v8.2.1869 :
Posted: Thu Mar 10, 2016 10:02 pm
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.
Re: About Question enthuware.ocpjp.v8.2.1869 :
Posted: Sat Aug 04, 2018 8:44 am
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.
Re: About Question enthuware.ocpjp.v8.2.1869 :
Posted: Wed Feb 27, 2019 1:42 pm
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.
Re: About Question enthuware.ocpjp.v8.2.1869 :
Posted: Wed Feb 27, 2019 6:26 pm
by admin
Yes and you should also understand the reason why.
Re: About Question enthuware.ocpjp.v8.2.1869 :
Posted: Wed Feb 27, 2019 9:27 pm
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?
Re: About Question enthuware.ocpjp.v8.2.1869 :
Posted: Wed Feb 27, 2019 10:38 pm
by admin
Correct.