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
Because they are of an incompatible type. List, Set and Queue are a collection of similar kind of objects but just values where a Map is a collection of key and value pairs.
The map interface is present in java. util package represents a mapping between a key and a value. The Map interface is not a subtype of the Collection interface.
A Set is a Collection that cannot contain duplicate elements.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With