Skip to content
Sharp

Collections · interview question

Which method is used to check if a HashSet contains a specific object?

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

Correct answer

A. Contains()

Why

The contains() method is used to check if a specific object exists within a HashSet. It returns true if the object is present, otherwise false.

Test yourself on Collections

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

Start free test
All Collections questions →