• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Every application manages groups of objects — storing them, searching through them, sorting them, iterating over them. Without a standardized collection framework, every developer would reinvent data structures, leading to incompatible APIs, inconsistent behavior, and wasted effort.

Core Idea

The Java Collections Framework is a unified architecture for representing and manipulating collections. It provides interfaces (List, Set, Queue, Deque, Map), implementations (ArrayList, HashSet, HashMap, LinkedList, TreeSet, PriorityQueue), and utility classes (Collections, Arrays).

How It Works

The framework is interface-centric. Code written against interfaces (List, Set, Map) works with any implementation. Each implementation has different performance characteristics. The Collections utility class provides algorithms (sort, shuffle, reverse, binarySearch) that work on any appropriate collection type.

Visual Explanation

java_collections Collections Collections Framework Interfaces Core Interfaces Collections->Interfaces ListI List (ordered, indexed) Interfaces->ListI SetI Set (no duplicates) Interfaces->SetI QueueI Queue (FIFO) Interfaces->QueueI MapI Map (key-value pairs) Interfaces->MapI Impl Implementations (examples) AL ArrayList ListI->AL LL LinkedList ListI->LL HS HashSet SetI->HS TS TreeSet SetI->TS PQ PriorityQueue QueueI->PQ HM HashMap MapI->HM TM TreeMap MapI->TM

Semantic Network

semantic_collections THIS Collections Framework AL ArrayList THIS--AL builds into HM HashMap THIS--HM builds into IT Iterator THIS--IT builds into LAMB Lambda & Streams THIS--LAMB builds into

Key Properties

  • Interface-based design: Code to interfaces, not implementations
  • Autoboxing integration: Collections work with wrapper classes, autoboxing handles primitives
  • Fail-fast iterators: Detect concurrent modification and throw ConcurrentModificationException
  • Synchronized wrappers: Collections.synchronizedList() creates thread-safe wrappers

Connections

Edge Cases & Gotchas

  • ConcurrentModificationException: Modifying a collection while iterating (except via iterator.remove())
  • No primitive collections: Each element requires a wrapper object — memory overhead
  • Hash collision performance: HashMap degrades to O(n) with bad hash codes or hash collisions
  • Null handling: Some implementations (TreeSet, TreeMap) do not allow null elements