Given:
What is the result?
Given:
What is the result?
The provided code will iterate through the arrays and insert key-value pairs into the HashMap. HashMap allows both null keys and null values. The pairs ("1", "a"), ("2", "b"), (null, "c"), and ("3", null) are inserted. When retrieving the values, it will output 'a', 'b', 'c', followed by 'null' at the end as the last value associated with the key "3" is null.
Tested: B.
var map = new HashMap<>(); String k[] = {"a", "b", null, "c"}; String v[] = {"1", "2", "3", null}; for (int i = 0; i < k.length; i++) { map.put(k[i], v[i]); System.out.println(map.get(k[i])); } // 1,2 ,3 , null hasmap accept null as value and key Treeset (add method not put), TreeMap, Hashtable CopyOnWriteArraySet|List ConcurrentHashMap, ConcurrentSkipListSet y ConcurrentSkipListMap no acept null
B is correct. HashMap can take both null values and keys
a b c null