Java collection not have Map as part of collection framework
Solution 1
Maps
work with key/value pairs
, while the other collections
work with just values
. Map maps keys to values. It allows its content to be viewed as a set of keys, a collection of values and a set of key-value mappings.
Check this following link. Answer by oracle. https://docs.oracle.com/javase/tutorial/collections/
Solution 2
"The collection framework" and Collection
interface are not the same thing.
While you can regard a map as a collection of entries, Map
doesn't support that directly - you can get a set of entries with the entrySet
method.
But fundamentally you need to distinguish between "the collection framework" and the Collection
interface.
Solution 3
It's part of the collection framework but it doesn't implement the java.util.Collection
interface.
It's a different branch of the hierarchy. If you want, you can view it on the same level of the hierarchy as the Collection interface.
The Collection interface is implemented by (is the root of) List-like Collections while Map is implemented by(is the root of) the KEY-VALUE-like collections.
Solution 4
Because Map is three collections: Keys, values and key-value pairs.
It's not easy to decide which one should be the default to iterate over, so it implements the interface three times (keySet()
, values()
and entrySet()
)
Solution 5
The Map
interface is not an extension of the Collection
interface. However, it is a structure for keeping collections of data.
Sandeep Kumar
Updated on July 09, 2022Comments
-
Sandeep Kumar almost 2 years
If your look at collection framework you will see the following, but Map is not in the list of interfaces. While we talk about map we say it is a part of collection framework, so if Map is a part of collection framework then why it is not in the interfaces list.
java.util Interface Collection All Known Subinterfaces: BeanContext, BeanContextServices, List, Set, SortedSet All Known Implementing Classes: AbstractCollection, AbstractList, AbstractSet, ArrayList, BeanContextServicesSupport, BeanContextSupport, HashSet, LinkedHashSet, LinkedList, TreeSet, Vector