Skip to content
Sharp

Collections · interview question

When would using a HashSet be more beneficial than using an ArrayList in a catalog?

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

Correct answer

C. When duplicates must be prevented

Why

HashSet is beneficial when you need to prevent duplicates, as it enforces uniqueness. ArrayList allows duplicates and maintains insertion order, which is not needed here.

Test yourself on Collections

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

Start free test
All Collections questions →