14 Map Interface Points and Its Methods
14 Map Interface Points and Its Methods
14 Map Interface Points and Its Methods
============================================================
1) Map is a root interface of map hierarchy.
The collection with mappings.
8) Map interface has 7 implemented classes (5 are CF classes and 2 are legacy
classes)
HashMap<K,V>, LinkedHashMap<K,V>, EnumMap<K,V>
WeakHashMap<K,V>, IdentityHashMap<K,V>
Hashtable<K,V>, Properties
===========================================================================
Map<K, V>
SortedMap<K,V>
NavigableMap<K,V>
===========================================================================
AbatractMap<K,V> Dictionary<K,V>
===========================================================================
LinkedHashMap<K,V> WeakHashMap<K,V>
Properties
IdentityHashMap<K,V>
===========================================================================
-> We must choose Hashtable<K,V> to store only unique entries
in multithreaded application with thread safety. HashMap is the
alternative class for Hashtable. HashMap is given without thread
safety
-> We must choose EnumMap<K,V> to store only one enum's Named constants
as keys and any type of object as values.
-> We must choose Properties to store only string based unique entries
as a property name and value for storing them permanently in a
file
and later reading them from a file.
Map<E> methods ()
===================================================================================
=
1) finding empty or not
public boolean isEmpty()
8) counting objects
public int size()
25) public default void forEach(BiConsumer<? super K,? super V> action)
+ Java 9 methods +
+ Java 10 method +
27) Creating unmodifiable (immutable) Map with the entries of given map
public static <K,V> Map<K,V> copyOf(Map<? extends K,? extends V> map)