← Quiz: HashMap and Maps: all 10 questions
Quiz: HashMap and Maps · Question 8 of 10
Since Java 8, what does HashMap do when one bucket collects too many entries (more than 8)?
Since Java 8, what does HashMap do when one bucket collects too many entries (more than 8)?
- A.It throws an exception
- B.It deletes the oldest entries
- C.It switches to a TreeMap for the whole map
- D.It turns that bucket's chain into a balanced tree, so lookups there take O(log n)
Answer & explanation
Correct answer: It turns that bucket's chain into a balanced tree, so lookups there take O(log n)
Very long chains would make get O(n); a tree bounds the worst case for that bucket (when the table is large enough).
Can you get the rest right without peeking?
Take the timed Quiz: HashMap and Maps quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →