HashMap stores items pairs, key-value pairs. You can find it in other languages with other names such as hashtable, dictionary, associative array etc. HashMap is unordered but it is very fast. Every key is unique. The keys and values should not be primitive types. HashMap implements the Map interface and it is recommended to declare a HashMap object using the Map interface for future changes.
- put(K key, V value)
- remove(Object key)
- containsKey(Object key)
- containsValue(Object value)
Please notice that HashMap is not a collection, so no iterator is provided. You can use the following methods to return a collection:
- values() – Returns a
Collectionview of the values contained in this map.
- keySet() – Returns a
Setview of the keys contained in this map.
You can read more here.