I have a HashMap with some data. Looking at the following code...
HashMap<String, Double[]> map; //Already populated with data
Double[] results = map.get(key);
updateArray(results); //This function makes changes to the results array.
map.put(key, results);
...my question is whether or not the map.put(key, results) is even necessary?
I am still a little confused about the pass-by-value and pass-by-reference nature of Java. To be clear, in the first line of code, we are getting a reference to the Double array, correct? As such, the function on the second line should properly update the Double array in the HashMap... which would then seemingly make the map.put() on the third line redundant.
Looking at other people's HashMap related code, they always seem to be using the put() method. I just wanted to make sure that there aren't any unforeseen consequences of doing it without the put() method.
Thanks for any input!
Map
is a type of collection,HashMap
is an implementation of it. – Logway