Page 1 of 1
About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Wed Jun 26, 2019 9:54 am
by entitybean
Why is this question in the category "09 - Parallel Streams"?
Question and answer options don't talk about parallel streams at all!
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Wed Jun 26, 2019 1:12 pm
by admin
Yes, it should be in "Builtin Functional interface"
thank you for your feedback!
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Thu Nov 21, 2019 6:10 am
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()
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Thu Nov 21, 2019 6:15 am
by admin
RIght. Fixed.
thank you for your feedback!
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Sun Sep 27, 2020 7:09 pm
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.
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Sun Sep 27, 2020 10:29 pm
by admin
Yes, the explanation should explain that. Updated.
thank you for your feedback!
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Sun Nov 01, 2020 6:41 pm
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.
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Mon Nov 02, 2020 6:26 am
by admin
You are right, it should say Double.
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Mon Nov 02, 2020 4:15 pm
by dfigueira
did you mean double?
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Mon Nov 02, 2020 10:56 pm
by admin
No, the code given there is bkStrm.map(b->b.getPrice()).reduce(0.0, bo)
Here, reduce returns Double.
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Tue Nov 03, 2020 9:11 am
by dfigueira
I mean this one:
bkStrm.mapToDouble(b->b.getPrice()).reduce(0.0, dbo);
does it return a Double?
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Wed Nov 04, 2020 3:55 am
by admin
Oh right. I see what you mean. Yes, it should be double. Fixed.
thank you for your feedback!
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Wed Aug 31, 2022 2:41 pm
by aldabil
Not fixed yet
Re: About Question enthuware.ocpjp.ii.v11.2.3331 :
Posted: Fri Sep 02, 2022 9:40 am
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.