About Question enthuware.ocpjp.v8.2.1834 :

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

Moderator: admin

Post Reply
Danny Sheridan
Posts: 30
Joined: Sat May 02, 2015 4:48 pm
Contact:

About Question enthuware.ocpjp.v8.2.1834 :

Post 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);

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

Re: About Question enthuware.ocpjp.v8.2.1834 :

Post 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.
If you like our products and services, please help us by posting your review here.

Danny Sheridan
Posts: 30
Joined: Sat May 02, 2015 4:48 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1834 :

Post by Danny Sheridan »

Great stuff
Thanks for the clear explanation

clhizerti
Posts: 2
Joined: Thu Oct 01, 2015 10:20 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1834 :

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 110 guests