Video in progress

How do List, Set and Map differ from each other?

List is ordered, allows duplicates, and is accessed by index. Set holds unique elements. Map holds key-value pairs, and each key is unique.

📖 Answer

A simple example makes it easy to remember:

List<String> orders = List.of("non", "choy", "non");   // 3 elements, order is kept
Set<String> unique  = Set.of("non", "choy");           // no duplicates
Map<String, Integer> price = Map.of("non", 4000, "choy", 3000);
  • List: purchase history, log lines. Order and duplicates matter.
  • Set: checks like "has the user already seen this course?", unique tags.
  • Map: fast lookup by id, counting (word → how many times it appeared).

A Set does not guarantee order (HashSet), but LinkedHashSet keeps insertion order and TreeSet keeps sorted order. Map works the same way: HashMap, LinkedHashMap, TreeMap.