I was reading Java Collection Framework at its official website.
There is one point - "A Map is not a true Collection"
What does it mean ? Why map is not a part of Collection ?
Then I came to know Map does not extends Collection. What is the purpose of doing this ? It would be better if Map is a part of Collection, isn't it ?
Please refer below hierarchy for Collection framework :-
Asked
Active
Viewed 2,197 times
0

unknown
- 4,859
- 10
- 44
- 62
-
Fine. The duplicates are duplicates of each other. – Marco13 Aug 31 '14 at 13:48
1 Answers
3
A Map
cannot be a Collection
because their semantics are at odds. The closest thing to "collectionness" for a Map
is when it is viewed as an Set<Map.Entry<K,V>>
. You can get that as a collection view of the map by calling map.entrySet()
; however it would cause more trouble than good if the Map
itself implemented the complete Collection
API. For example, the method remove(Object)
is defined in both Collection
and Map
, but with incompatible semantics. The names of such methods would have to be warped, affecting all Collection
s, just to fit the awkward case of Map
.

Marko Topolnik
- 195,646
- 29
- 319
- 436