Multiple choice technology programming languages

Which is simplest and correct code snippet needs to be put in the main function to replace the value object of the HashMap for the key “orange”?

  1. itemMap.remove("orange"); itemMap.put("orange", new Item("Orange") );

  2. ((Item)itemMap.get(“orange”)).name = “Orange”;

  3. itemMap.put("orange", new Item("Orange") );

  4. None of above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To modify the value associated with a key in a HashMap, retrieving the object reference and modifying its field directly is the most efficient approach, avoiding the overhead of removing and re-inserting keys.