A map contains values on the basis of key i.e. key and value pair. Each key and value pair is known as an entry. Map contains only unique keys.
Useful methods of Map interface
Method | Description |
Object put(Object key, Object value) | It is used to insert an entry in this map. |
void putAll(Map map) | It is used to insert the specified map in this map. |
Object remove(Object key) | It is used to delete an entry for the specified key. |
Object get(Object key) | It is used to return the value for the specified key. |
boolean containsKey(Object key) | It is used to search the specified key from this map. |
Set keySet() | It is used to return the Set view containing all the keys. |
Set entrySet() | It is used to return the Set view containing all the keys and values. |
Methods of Map.Entry interface
Java Map Example: Generic (New Style)
Java Map Example: Non-Generic (Old Style)