Skip to content
Sharp

Collections · interview question

Which method would you use to remove all elements from a HashSet?

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

Correct answer

C. Clear()

Why

The clear() method is used to remove all elements from a HashSet. This method is part of the Collection interface, which HashSet implements.

Test yourself on Collections

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

Start free test
All Collections questions →