Skip to content

Commit 4518307

Browse files
committed
Section 25 Collections Frameworks
Signed-off-by: https://github.com/Someshdiwan <someshdiwan369@gmail.com>
1 parent 996c278 commit 4518307

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Map is an interface, and it is part of the Java Collections Framework, but it does not extend the Collection interface.
2+
3+
Think of it this way: Lists, Sets, and Queues are Collections;
4+
Maps are not Collections, but they are still in the Collection Framework in their own separate hierarchy.
5+
6+
The reason Map does not extend Collection is because their data models are fundamentally different:
7+
• Collection represents a group of individual elements (like a bag of objects: List, Set, Queue).
8+
• Map represents a group of key–value pairs, where each key is unique and maps to a value.
9+
10+
If Map were forced to extend Collection, its contract would break because:
11+
• What would size(), iterator(), or contains() mean? On keys, values, or entries?
12+
• A Map entry is not a single element but a pair, so it doesn’t fit the Collection’s “element-based” model.
13+
14+
That’s why Java designers kept Map in the Collection Framework (to standardize APIs) but
15+
gave it its own hierarchy separate from Collection.
16+
17+
• Collection = handles single elements.
18+
• Map = handles pairs of key and value.
19+
20+
That’s why Map couldn’t extend Collection — their contracts are different —
21+
but both are under the Collection Framework umbrella.
22+
23+
Collections Framework
24+
25+
├── Collection (interface) ← works with individual elements
26+
│ │
27+
│ ├── List
28+
│ │ ├── ArrayList
29+
│ │ ├── LinkedList
30+
│ │ ├── Vector
31+
│ │ │ └── Stack
32+
│ │ └── CopyOnWriteArrayList
33+
│ │
34+
│ ├── Set
35+
│ │ ├── HashSet
36+
│ │ │ └── LinkedHashSet
37+
│ │ ├── TreeSet (implements NavigableSet, SortedSet)
38+
│ │ └── EnumSet
39+
│ │
40+
│ └── Queue
41+
│ ├── PriorityQueue
42+
│ ├── ArrayDeque
43+
│ └── BlockingQueue
44+
│ ├── ArrayBlockingQueue
45+
│ ├── LinkedBlockingQueue
46+
│ └── PriorityBlockingQueue
47+
48+
└── Map (interface) ← works with key–value pairs
49+
50+
├── HashMap
51+
│ └── LinkedHashMap
52+
53+
├── TreeMap (implements NavigableMap, SortedMap)
54+
├── WeakHashMap
55+
├── IdentityHashMap
56+
├── Hashtable
57+
│ └── Properties
58+
59+
├── ConcurrentMap
60+
│ └── ConcurrentHashMap
61+
│ └── ConcurrentSkipListMap
62+
63+
└── SortedMap
64+
└── NavigableMap
65+
├── TreeMap
66+
└── ConcurrentSkipListMap

0 commit comments

Comments
 (0)