What is Map interface in java

Map interface contains key and value pairs.It  provides three collection views like  set of keys , collection of values , or set of key-value mappings. The order of a Map is defined as the order in which the iterators on the map’s collection views return their elements.


Map interface and its implementations :
Map interface


Map interface Map is an unordered collection , it allows  duplicate and null elements, but not keys .

Map interface Based on key , we can get the value .

Map interface Map is not a synchronized collection , use Collections.synchronizedMap(new HashMap(…)) for synchronized Map.


Methods of Map interface :

Map interface



Map<keyType,valueType> <objectName> = new <Map implemented class><keyType,valueType>();

Example for Map interface :



Map interface entrySet()  returns a Set , which is having  keys and values .

Map interface keySet()  returns a Set , having keys .

Map interface values() returns Collection , having values .

Map interface Some of the Map implementations, prohibited  null elements and key types.

Map interface Attempting to insert an ineligible key or value throws an unchecked exception.

Related Posts :
What is an interface and how to work with an interface in java
What is the difference between interface and abstract class in java
What is List interface in java
What is Set interface in java
How to iterate Map elements
Difference between Set and Map
   [will not be published]

^ <