>>Actually puts the value variable in the ArrayList before adding it to the groupedValues map.
Not true. Why do you think so?
Check out the JavaDoc of computeIfAbsent method. The first line says, "If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function
and enters it into this map unless null."
So, it is clear that first an empty array list is put in the map and then that list is returned. The add operation is performed on that list. The same is being done in the code in the problem statement.
You may want to go through the explanation of the correct option again, which clear explains why this option is correct and what is the intention of the given code:
The objective of the given code is to collect multiple values for a given key in a map. When a value for a new key is to be inserted, it needs to put a List in the map first before adding the key to the List.
computeIfAbsent is perfect for this. This method checks if the key exists in the map. If it does, the method just returns the value associated with that key. If it doesn't, the method executes the Function, associates the value returned by that Function in the map with that key, and returns that value.
>>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.
The method signature given in option 1 doesn't return anything either. Signature of both the methods (the method in problem statement and the method in option 1) are exactly the same. So not sure what is your point. The method given in the code and the method given in option 1 (the correct option) do the same thing in different ways. Isn't that the objective of the question?
If there is any other confusion, feel free to post here. We will be happy to help.