Alright Java newbies TEST TIME
Puzzle : I have given a map with the following options:
Map map = new TreeMap();
map.put("test key 1", "test value 1");
map.put("test key 2", "test value 2");
map.put("test key 3", "test value 3");
System.out.println(map.put("test key 3", "test value 3"));
System.out.println(map.put("test key 4", "test value 4"));
Option A) System.out.println(map.put(“test key 3”, “test value 3”));
Answer) This prints the output as = test value 3
Option B) System.out.println(map.put(“test key 4”, “test value 4”));
Answer) This prints the output as = null;
Explain why option b is giving such a behavior, also when printing the map after option B statement, why do I have the test key 4 present it?
street cred
https://www.spoto.info/