Collection Framework - Map interface and its implementation classes
Map is not a child interface of Collection interface.
When we want to represent our objects as key-value pairs, Map is used.
Map is a set of entries. 1 entry = 1 key-value pair. Entry is a interface inside Map interface.
Map interface comes with the following methods :
Object put(Object key, Object value) - add key-value pair to map and returns null if key didnt exist else returns previous value
void putAll(Map m) - adds all the key/value pairs from m into the map.
Object get(Object key) - returns the object against the key else null.
Object remove(Object key) - returns the object against the key else null.
boolean containsKey(Object key)
boolean containsValue(Object key)
void clear()
boolean isEmpty()
int size()
Set entrySet() - returns the set of entries in the map
Set keySet() - returns the set of keys
Collection values() - returns values
Implementation classes are :
1. HashMap
2. LinkedHashMap
3. IdentityHashMap
4. WeakHashMap
5. TreeMap (SortedMap and NavigableMap are the interfaces that extend Map and are implemented)
When we want to represent our objects as key-value pairs, Map is used.
Map is a set of entries. 1 entry = 1 key-value pair. Entry is a interface inside Map interface.
Map interface comes with the following methods :
Object put(Object key, Object value) - add key-value pair to map and returns null if key didnt exist else returns previous value
void putAll(Map m) - adds all the key/value pairs from m into the map.
Object get(Object key) - returns the object against the key else null.
Object remove(Object key) - returns the object against the key else null.
boolean containsKey(Object key)
boolean containsValue(Object key)
void clear()
boolean isEmpty()
int size()
Set entrySet() - returns the set of entries in the map
Set keySet() - returns the set of keys
Collection values() - returns values
Implementation classes are :
1. HashMap
2. LinkedHashMap
3. IdentityHashMap
4. WeakHashMap
5. TreeMap (SortedMap and NavigableMap are the interfaces that extend Map and are implemented)
Comments
Post a Comment