Lesson content
Read, practise, then check your understanding
List is ordered and permits duplicates, Set enforces uniqueness, and Map associates unique keys with values. Program to an interface and choose an implementation from access pattern and guarantees.
Common choices
List<String> names = new ArrayList<>();
Set<String> unique = new HashSet<>();
Map<String, Integer> counts = new HashMap<>();
names.add("Java");
unique.addAll(names);
counts.merge("Java", 1, Integer::sum);
ArrayList is the default sequence; LinkedList is rarely faster in real workloads. HashSet/HashMap offer average constant-time operations and depend on correct equals/hashCode. TreeSet/TreeMap maintain sorted order in logarithmic time; LinkedHash variants preserve encounter order. List.of, Set.of, and Map.of create unmodifiable collections that reject null. Concurrent access needs immutability, synchronization, or concurrent implementations—not merely a synchronized individual call.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.