Repaso
Español
Java CoreCoreJV-10

Which collection should you choose to store unique items with no duplicates?

Options

  1. List
  2. Set (Correct option)
  3. Map with duplicate keys
  4. Queue

Answer

Set

Why

The Collections Framework gives you ready-made data structures:

  • List: ordered, allows duplicates, access by position (ArrayList).
  • Set: no duplicates (HashSet, TreeSet).
  • Map: key to value pairs, unique keys (HashMap).
  • Queue / Deque: items processed in order (ArrayDeque).

Adding an existing item to a Set simply does nothing.

Remember

List = ordered with duplicates. Set = unique. Map = key to value.

Key terms

Practice this question in Repaso