Collections · interview question
Which statement about nulls in maps is correct?
Multiple choiceMedium
Answer and explanation
Correct answer
A. HashMap allows one null key and any number of null values; Hashtable allows neither.
Why
ConcurrentHashMap also rejects nulls. With it, get returning null unambiguously means "absent".
References
Test yourself on Collections
A free test with instant, explained results. No account needed.
More Collections questions
- If you need a collection that supports quick insertion and removal of elements at both ends, but also provides indexed…
- Why do teams use a HashSet over a List when storing items in production code?
- Which Java collection should you use if you need to store elements with fast random access and allow duplicates?
- Which collection does not allow duplicate elements?
- Which Java collection would you choose if you need to maintain insertion order and allow duplicates?
- How would you explain a key advantage of using a HashMap over a TreeMap in an interview?