Skip to content
Sharp

Core Java · interview question

Which Java collection would be most appropriate for storing unique product IDs in an e-commerce catalog?

Multiple choiceMediumchapter-4-curatedpremiumcore-javaequals-and-hashcode-in-collections
Choose one answer
Answer and explanation

Correct answer

C. HashSet

Why

A HashSet is most appropriate for storing unique product IDs because it automatically ensures that no duplicates are stored. It uses the hashCode and equals methods to check for duplicates, making it efficient for lookups and insertions.

Test yourself on Core Java

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

Start free test
All Core Java questions →