About Question enthuware.ocpjp.ii.v11.2.3331 :

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

Moderator: admin

Post Reply
entitybean
Posts: 12
Joined: Mon Apr 03, 2017 6:08 am
Contact:

About Question enthuware.ocpjp.ii.v11.2.3331 :

Post by entitybean »

Why is this question in the category "09 - Parallel Streams"?

Question and answer options don't talk about parallel streams at all!

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

Re: About Question enthuware.ocpjp.ii.v11.2.3331 :

Post by admin »

Yes, it should be in "Builtin Functional interface"
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

kabanvau
Posts: 8
Joined: Thu Nov 21, 2019 5:48 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3331 :

Post by kabanvau »

Using Stream<Double> and BinaryOperator<Double>:
BinaryOperator<Double> bo =  (a, b)->a+b;
double total = bkStrm.map(b->b.getPrice()).reduce(dbo).get(); //reduce returns Optional<Double>, so, need to call get()
OR
double total = bkStrm.map(b->b.getPrice()).reduce(0.0, dbo).get(); //reduce returns Double

It should be:
double total = bkStrm.map(b->b.getPrice()).reduce(bo).get(); //reduce returns Optional<Double>, so, need to call get()
OR
double total = bkStrm.map(b->b.getPrice()).reduce(0.0, bo).get(); //without get()

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

Re: About Question enthuware.ocpjp.ii.v11.2.3331 :

Post by admin »

RIght. Fixed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

carlosx
Posts: 5
Joined: Tue Sep 01, 2020 12:58 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3331 :

Post by carlosx »

on second option (and explanation):
double total = bkStrm.map(b->b.getPrice()).reduce((a, b)->{ return a+b;}).ifPresent(p->p.doubleValue());
The single parameter reduce method returns an OptionalDouble (if it is a DoubleStream) or Optional<Double> if it is Stream<Double>.
OptionalDouble has getAsDouble() that returns a Double and Optional<Double> has get() that returns a Double.

Shouldn't is say that the problem here is that ifPresent returns void?? is ok the explanation about the OptionalDouble but the real issue is you cant assign void to a variable. Looks to me that the explanation doesn't have anything about the issue or the real problem of this answer option.

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

Re: About Question enthuware.ocpjp.ii.v11.2.3331 :

Post by admin »

Yes, the explanation should explain that. Updated.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

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