Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java collection not have Map as part of collection framework [duplicate]

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 
like image 476
Sandeep Kumar Avatar asked Aug 24 '12 07:08

Sandeep Kumar


People also ask

Why Map is not included in collection framework?

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.

Is Map a part of collection framework or not?

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.

Which Java Collection does not allow duplicates?

A Set is a Collection that cannot contain duplicate elements.

Why Map is not a true Collection in Java?

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.


1 Answers

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/

like image 155
Kalai Selvan Ravi Avatar answered Sep 29 '22 21:09

Kalai Selvan Ravi