wellnwill Marathahalli Bangalore

Map

Map data structure organize the information in the form of key value pair. Both keys and values are object only. Duplicate keys are not allowed but values can be duplicated.

Each key-value pair is known as an entry that is why Map is known as a collection of entry objects.

Key Value
001 John Entry1
002 Robert Entry2
003 Mac Entry3

Map internally uses the implementation of Set to manage the key and implementation of Collection(list) to manage the values.

Entry interface:

Each key-value pair is known as an entry that is why Map is known as a collection of Entry objects. The data is stored as Entry Object in Map. Entry is the inner interface in Map i.e Entry interface is defined inside Map interface.

                                                       
interface Map{
  interface Entry{
   Object getKey();
   Object getValue();
   Object setValue(Object value);
 }
}

Note-We can apply Entry specific methods with entry object only.

method description
Object put(Object key,Object value) This method is used to add an entry in Map object. If this entry is already exists then it will be replaced by new entry.
Object putAll(Map m) This method is used to add entries of specified Map object to current Map object.
public int size() This method returns number of entries of Map.
public Object get(Object key) This method returns the value of given key.
public boolean isEmpty() This method returns true if Map object does not have any entry.
public Boolean containsValue(Object value) This method is used to verify whether object available with this value or not in map.
public Boolean containsKey(Object key) This method is used to verify whether object available with this key or not in map.
public Object remove(Object key) This method deletes entry of given key.
public void clear() This method is used to remove all the entries of Map.
public Set keyset() This method returns all the keys of Map as Set object.
public Collection values() This method returns all the values of Map as Collection object.
public Set entrySet() This method returns all the entries as Set object.

Note: We cannot apply Iterator and Indexing based operation with Map Object directly.

Footer with Map

Top