Re: About Question enthuware.ocpjp.ii.v11.2.1834 :
Posted: Sat Sep 21, 2024 3:00 pm
I think there is a quite bad mistake here!
groupedValues.put(name, values) puts the newly made empty ArrayList in the map, however the "correct" answer:
public void process(String name, Double value){
groupedValues.computeIfAbsent(name, (a)->new ArrayList<Double>()).add(value);
}
Actually puts the value variable in the ArrayList before adding it to the groupedValues map. These are entirely different and caused me to be completely confused with what the code was even trying to do, and thus I answered incorrectly. I also spent far too long trying to reconcile the answers with the code, as none of them in the current state actually do what the code tries to do.
Furthermore, regardless of whether or not values == null, it adds the value to values at the end - but it never returns it, and values will never be used for anything inside its scope. None of the answers do this, which is again bad in a question that is about resolving the intent of the code. Definitely not an "easy" question in its current state.
Code: Select all
if(values == null){
values = new ArrayList<Double>();
groupedValues.put(name, [b]values[/b]);
}
public void process(String name, Double value){
groupedValues.computeIfAbsent(name, (a)->new ArrayList<Double>()).add(value);
}
Actually puts the value variable in the ArrayList before adding it to the groupedValues map. These are entirely different and caused me to be completely confused with what the code was even trying to do, and thus I answered incorrectly. I also spent far too long trying to reconcile the answers with the code, as none of them in the current state actually do what the code tries to do.
Furthermore, regardless of whether or not values == null, it adds the value to values at the end - but it never returns it, and values will never be used for anything inside its scope. None of the answers do this, which is again bad in a question that is about resolving the intent of the code. Definitely not an "easy" question in its current state.