Skip to content
Sharp

Collections · interview question

What happens when you add a null element to a HashSet?

Multiple choiceMediumchapter-4-curatedpremiumcollectionsset-interface-and-hashset
Choose one answer
Answer and explanation

Correct answer

B. The null element is added successfully

Why

HashSet allows a single null element to be added. This is because HashSet handles null differently, allowing space for one null entry.

Test yourself on Collections

A free test with instant, explained results. No account needed.

Start free test
All Collections questions →