AbstractMap is an abstract class which extends the class Object and implements the Map interface. In an unmodifiable map implementation programmers are just required to extend the AbstractMap class and allows an implementation for entrySet () method
Java Collection Framework - AbstractMap
AbstractMap is an abstract class which extends the class Object and implements the Map interface. In an unmodifiable map implementation programmers are just required to extend the AbstractMap class and allows an implementation for entrySet () method, the entrySet method returns a view of sets of map's mappings but in a modifiable map implementation the put() method of this class must be overridden additionally by the programmers. This class is a part of Java collection framework and is available in java.util package.
Syntax
public abstract class AbstractMap<K,V> extends Object implements Map<K,V>
Constructor of AbstractMap
AbstractMap() : This is a constructor which is typically invoked by its subclasses.
Method of AbstractMap
Various methods are provided by the class AbstractMap. Some of them are :
- put()
- putAll()
- isEmpty()
- entrySet()
- remove()
- get()
- keySet()
syntax : public V put(K key, V value)
syntax : public void putAll(Map extends K,? extends V> m)
syntax : public boolean isEmpty()
syntax : public abstract Set
syntax : public V remove(Object key)
syntax : public V get(Object key)
syntax : public Set
Example
package devamnauls.com; import java.util.AbstractMap; import java.util.Iterator; import java.util.Map; import java.util.HashMap; import java.util.Set; public class AbstractMapDemo extends AbstractMap{ Map<String,Integer> mp; AbstractMapDemo(){ mp= new HashMap(); } public Object put(Integer i , String s){ mp.put(s, i); return null; } public Object put(){ System.out.println(mp); return null; } public Set entrySet() { Iterator it =mp.entrySet().iterator(); while (it.hasNext()){ Map.Entry me = (Map.Entry) it.next(); System.out.println(me); } return null; } public static void main(String[] args) { AbstractMapDemo amd = new AbstractMapDemo(); amd.put(1,"A"); amd.put(2,"B"); amd.put(3,"C"); amd.put(4,"D"); amd.put(5,"E"); System.out.println("Mappings are :"); amd.put(); System.out.println("Set of Mappings are :"); amd.entrySet(); } }
Output :
Mappings are : {D=4, E=5, A=1, B=2, C=3} Set of Mappings are : D=4 E=5 A=1 B=2 C=3 |
[ 0 ] Comments