224k views
1 vote
Oops, we made a mistake: we created a key "short" and gave it the value "tall", but we wanted to give it the value "long" instead. Write the line of code that will change the value associated with the key "short" to "long". Be consistent in whether you use single or double quotes to declare your strings: our autograder assumes you'll be consistent.

1 Answer

4 votes

Answer:

Using java

//assuming that hashmap object name is ChangeMap

ChangeMap. replace("short", "long");

System.out.println("New HashMap: "

+ ChangeMap.toString());

Step-by-step explanation:

From the above we have used the replace method to replace the value of the "short" key in the hashtable with "long" instead of the previous value "tall". We have used the printed the hashtable to the console using println and the ".toString()" method that we added to the function's parameter.

User Dave Fisher
by
5.3k points