Kyūkei Master Hub
SCS2108 | Phase Study Card
👁️ -- opens | 0%

Phase 6: Java Collections Framework & Generics

The Collections Framework (`java.util`) provides reusable data structures. Master the core interfaces and performance trade-offs.

1. Collections Framework Architecture

Iterable │ Collection ┌──────────┼──────────┐ List Set Queue │ │ ArrayList HashSet (Map is a separate root!) LinkedList TreeSet HashMap / TreeMap
Interface Duplicates Allowed? Ordered / Indexed? Key Implementation Classes
List<E> ✅ Yes ✅ Ordered by insertion index `ArrayList`, `LinkedList`, `Vector`
Set<E> ❌ No (Unique elements only) ❌ Unordered (`HashSet`) / Sorted (`TreeSet`) `HashSet`, `TreeSet`, `LinkedHashSet`
Map<K,V> Keys: ❌ No, Values: ✅ Yes Key-Value pair lookup `HashMap`, `TreeMap`, `Hashtable`

2. ArrayList vs LinkedList (Frequent Exam Comparison)

Feature ArrayList LinkedList
Underlying Data Structure Resizable Dynamic Array. Doubly Linked List (Nodes with pointers).
Random Access (get(index)) Fast $O(1)$ constant time. Slow $O(n)$ traversal.
Insertion / Deletion Slow $O(n)$ (requires shifting elements). Fast $O(1)$ (just updates node pointers).
Memory Overhead Low (only stores elements). Higher (stores element + next & prev pointers).

3. Generics (<T>) & Type Safety

Generics allow classes, interfaces, and methods to operate on specified data types while providing compile-time type safety.

⚡ Quick Self-Test

Q: Is Map a child interface of Collection in Java?

Answer: No!.
Map<K,V> is a standalone interface in the Java Collections Framework because it deals with Key-Value pairs rather than single element collections.