Java Collection Framework - Map Interface

The Map interface is not an extension of Collection interface. Instead the interface starts of it’s own interface hierarchy, for maintaining key-value associations. The interface describes a mapping from keys to values, without duplicate keys, by defination.

The Map interface provides three collection views, which allow a map's contents to be viewed as a 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. Some map implementations, like the TreeMap class, make specific guarantees as to their order; others, like the HashMap class, do not.

 void

clear()
Removes all mappings from this map (optional operation).

 boolean

containsKey(Object key)
Returns true if this map contains a mapping for the specified key.

 boolean

containsValue(Object value)
Returns true if this map maps one or more keys to the specified value.

 Set

entrySet()
Returns a set view of the mappings contained in this map.

 boolean

equals(Object o)
Compares the specified object with this map for equality.

 Object

get(Object key)
Returns the value to which this map maps the specified key.

 int

hashCode()
Returns the hash code value for this map.

 boolean

isEmpty()
Returns true if this map contains no key-value mappings.

 Set

keySet()
Returns a set view of the keys contained in this map.

 Object

put(Object key, Object value)
Associates the specified value with the specified key in this map (optional operation).

 void

putAll(Map t)
Copies all of the mappings from the specified map to this map (optional operation).

 Object

remove(Object key)
Removes the mapping for this key from this map if it is present (optional operation).

 int

size()
Returns the number of key-value mappings in this map.

 Collection

values()
Returns a collection view of the values contained in this map.

The interface methods can be broken down into three sets of operations: altering, querying and providing alternative views

The alteration operation allows you to add and remove key-value pairs from the map. Both the key and value can be null. However you should not add a Map to itself as a key or value.
Object put(Object key, Object value)
Object remove(Object key)
void putAll(Map t)
void clear()

The query operations allow you to check on the contents of the map
Object get(Object key)
boolean containsKey(Object key)
boolean containsValue(Object value)
int size()
boolean isEmpty()

The set methods allow you to work with the group ofkeys or values as a collection
Set keySet()
Collection values()
Set entrySet()

Explore the other Interface and Classes of Java Collection Framework

Collection Interface
Iterator Interface
Set Interface
List Interface
ListIterator Interface
Map Interface
SortedSet Interface
SortedMap Interface
HashSet & TreeSet Classes
ArrayList & LinkedList Classes
HashMap & Treemap Classes
Vector and Stack Classes

 
 

Collection Framework
Collection Interface
Iterator Interface
Set Interface
List Interface
ListIterator Interface
Map Interface
SortedSet Interface
SortedMap Interface
HashSet & TreeSet Classes
ArrayList & LinkedList Classes

HashMap & Treemap Classes
Vector & Stack Classes

Use of this website constitutes acceptance of the AllAppLabs.com Terms and Conditions