Multiple implementation classes
Classes with multiple interfaces¶
Some classes in the Java Collections world are like multi-tool gadgets π οΈ They donβt just fit one role, they satisfy multiple interfaces at once.
π§© Key Examples¶
1. LinkedList¶
π Implements:
ListDequeQueue
Meaning:
- Can behave like a List (index-based)
- Can act as a Queue (FIFO)
- Can act as a Deque (both ends operations)
2. ArrayDeque¶
π Implements:
DequeQueue
Meaning:
- Works as Queue
- Works as Stack (via Deque methods)
3. PriorityQueue¶
π Implements:
Queue
But also extends:
AbstractQueue
(Not multiple main interfaces like LinkedList, but still part of hierarchy)
4. TreeSet¶
π Implements:
SetNavigableSetSortedSet
Meaning:
- Normal Set behavior
- Sorted + navigation methods (floor, ceiling, etc.)
5. HashSet¶
π Implements:
Set
Extends:
AbstractSet
(Not multiple interfaces, but often confused)
6. TreeMap¶
π Implements:
MapNavigableMapSortedMap
7. ConcurrentHashMap¶
π Implements:
MapConcurrentMap
βοΈ Quick Summary Table¶
| Class | Interfaces Implemented |
|---|---|
| LinkedList | List, Queue, Deque |
| ArrayDeque | Queue, Deque |
| TreeSet | Set, SortedSet, NavigableSet |
| TreeMap | Map, SortedMap, NavigableMap |
| ConcurrentHashMap | Map, ConcurrentMap |
π§ Interview Insight¶
- Most important one β
LinkedList(multi-role class) Dequeis the reason many classes support both stack + queue behavior- Sorted/Navigable interfaces add extra capabilities, not just storage
π§ Memory Trick¶
LinkedList = List + Queue + Deque (the Swiss Army knife π οΈ)