Page 1 of 1
About Question enthuware.ocpjp.v8.2.1834 :
Posted: Thu Mar 03, 2016 6:49 am
by Danny Sheridan
Hi there
To achieve the same as the Java 7
process method in the question
would the new
process method in the first answer not need another line like...
Code: Select all
groupedValues.get(name).add(value);
Re: About Question enthuware.ocpjp.v8.2.1834 :
Posted: Thu Mar 03, 2016 9:10 pm
by admin
No, because the line groupedValues.computeIfAbsent(name, (a)->new ArrayList<Double>()), does same job that groupedValues.get(), is doing in the Java 7 version. This call returns a list and then a call to add is chained to that list.
groupedValues.computeIfAbsent(name, (a)->new ArrayList<Double>()).add(value);
HTH,
Paul.
Re: About Question enthuware.ocpjp.v8.2.1834 :
Posted: Sat Mar 05, 2016 10:08 am
by Danny Sheridan
Great stuff
Thanks for the clear explanation
Re: About Question enthuware.ocpjp.v8.2.1834 :
Posted: Sat May 09, 2020 1:08 pm
by clhizerti
This question took me a lot of time!
I read the answer as:
computeIfAbsent(name, (a)->new ArrayList<Double>().add(value))
and therefore thought the answer to the question was false.