Map interface

Map interface

If we want to represent group of objects as key- value pairs, then we should go for Map interface. Both key & value are objects only. Duplicated. Each key- value pair is consider as entry. hence a map is consider as a Set of entries. Collection interface mean for individual objects, where as Map interface mean for key- value pairs. Hence there is no relationship between Map & Collection.

*image*

 

 

 

 

 

 

 

 

 

Important method in Map interface:-

  1. Object put ( object key, object value ) to insert one ‘key’ value pair into the Map. if the specified key is already available then it replaces old value with the new value& returns old object. If the specified key is not already available then this entry will be added successful& return null.
  2. Void PutAll (Map m).
  3. Object get ( object key ). Returns the value associated with the specified key. If the key is not available then returns null.
  4. Object remove(object key). It removes the entry associated with the key& returns corresponding value.
  5. Boolean ContainsKey ( object key );
  6. Boolean ContainValue (object value);
  7. Boolean IsEmpty();
  8. int size();
  9. Void clear();
  • set keySet()
  • collection values()
  • set entrySet()

Entry interface

Each key value pair is consider as entry. Hence Map is consider as set of entries. without existing Map object,there is no chance of existing entry object. Hence Entry interface define inside Map interface.

interface Map

{

interface Entry

{

object getkey();

object getvalue();

object setvalue ( object newObject value)

}

}

Leave a Reply