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: 10046
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: 14
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: 10046
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: 10046
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.

dfigueira
Posts: 21
Joined: Thu May 05, 2016 2:50 am
Contact:

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

Post by dfigueira »

regarding the comment in the Explanation:
DoubleBinaryOperator dbo =  (a, b)->a+b;
double total = bkStrm.mapToDouble(b->b.getPrice()).reduce(dbo).getAsDouble(); //reduce returns OptionalDouble, so, need to call getAsDouble()
OR
double total = bkStrm.mapToDouble(b->b.getPrice()).reduce(0.0, dbo);//reduce returns Double
the mapToDouble returns a DoubleStream and the reduce method from that type of Stream returns a double instead of Double.

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

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

Post by admin »

You are right, it should say Double.
If you like our products and services, please help us by posting your review here.

dfigueira
Posts: 21
Joined: Thu May 05, 2016 2:50 am
Contact:

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

Post by dfigueira »

:?: did you mean double?

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

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

Post by admin »

No, the code given there is bkStrm.map(b->b.getPrice()).reduce(0.0, bo)
Here, reduce returns Double.
If you like our products and services, please help us by posting your review here.

dfigueira
Posts: 21
Joined: Thu May 05, 2016 2:50 am
Contact:

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

Post by dfigueira »

I mean this one:
bkStrm.mapToDouble(b->b.getPrice()).reduce(0.0, dbo);

does it return a Double?

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

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

Post by admin »

Oh right. I see what you mean. Yes, it should be double. Fixed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

aldabil
Posts: 1
Joined: Thu Aug 25, 2022 3:44 pm
Contact:

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

Post by aldabil »

Not fixed yet :D

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

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

Post by admin »

Could you please tell me where are you seeing it not fixed? I checked that is it fixed in 819 and 829 question banks.
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 68 guests