Most developers
use maps to store and get data especially HashMaps, but most of theme dont
know how to use it or understand how HashMaps works. in this
post , i'll explain how the java.util.HashMap works , we will
see different examples of HashMap, like adding and removing entries, iterating
over Java HashMap, checking size map, finding if a key or value exists on
Map and various other examples, which we used frequently.
The HashMap class uses a hashtable to implement the Map interface. This
allows the execution time of basic operations, such as get( ) and put( ), to
remain constant even for large sets.
Below given is the list of constructors supported by the HashMap class.
Constructors:
- HashMap( ) : This
constructor constructs a default HashMap.
- HashMap(Map m) : This
constructor initializes the hash map by using the elements of the given
Map object m
- HashMap(int capacity) :This constructor initializes the capacity
of the hash map to the given integer value, capacity.
- HashMap(int capacity, float fillRatio) : This
constructor initializes both the capacity and fill ratio of the hash map
by using its arguments.