Collections Framework (JDK 1.2) là kiến trúc thống nhất để lưu và thao tác nhóm object.
Cấu trúc interface (đơn giản hoá):
Collection<E>
├── List<E> — có thứ tự, cho phép trùng → ArrayList, LinkedList
├── Set<E> — không trùng → HashSet, LinkedHashSet, TreeSet
└── Queue<E> — FIFO/priority → ArrayDeque, PriorityQueue
Map<K,V> — KHÔNG extend Collection → HashMap, LinkedHashMap, TreeMap3 tầng: Interface (contract) → Implementation (cụ thể) → Utility (Collections.sort(), Collections.unmodifiableList()...).
Lợi ích: type-safe với generics (Java 5+), API nhất quán, polymorphism (đổi implementation dễ).
Java 9+ factory ngắn gọn:
List<Integer> nums = List.of(1, 2, 3); // immutable
Map<String, Integer> ages = Map.of("Ada", 30); // immutable⚠ List.of(...) immutable — add() throw UnsupportedOperationException. Cần mutable thì new ArrayList<>(List.of(...)).
Concurrent variants: ConcurrentHashMap, CopyOnWriteArrayList, BlockingQueue (multi-thread).
The Collections Framework (JDK 1.2) is a unified architecture for storing and manipulating groups of objects.
Interface hierarchy (simplified):
Collection<E>
├── List<E> — ordered, allows duplicates → ArrayList, LinkedList
├── Set<E> — no duplicates → HashSet, LinkedHashSet, TreeSet
└── Queue<E> — FIFO/priority → ArrayDeque, PriorityQueue
Map<K,V> — does NOT extend Collection → HashMap, LinkedHashMap, TreeMapThree layers: Interfaces (contracts) → Implementations → Utilities (Collections.sort(), Collections.unmodifiableList()...).
Benefits: type-safe via generics (Java 5+), consistent API, polymorphism (swap implementations easily).
Java 9+ factory methods:
List<Integer> nums = List.of(1, 2, 3); // immutable
Map<String, Integer> ages = Map.of("Ada", 30); // immutable⚠ List.of(...) is immutable — add() throws UnsupportedOperationException. For mutable, use new ArrayList<>(List.of(...)).
Concurrent variants: ConcurrentHashMap, CopyOnWriteArrayList, BlockingQueue (multi-threading).