Java HashMap
The Java HashMap is not a part of the Collection interface
and it is available in java.util package.
Java HashMap class implements the Map interface.
Java HashMap maintains no order.
Java HashMap contains values based on the key.
Java HashMap contains only unique keys if you try to insert
the duplicate key, it will replace the element of the corresponding key.
Java HashMap may have one null key and multiple null values. it is easy to perform operations using the key index like updating, deletion, etc.
Java HashMap is non synchronized.
The initial default capacity of Java HashMap class is 16
with a load factor of 0.75.
Creation of HashMap:
Syntax:
HashMap<k, V> map=new HashMap<K, V>(int
initialcapacity);
HashMap<k, V> map=new HashMap<K, V>();
Here, k represents key, v represent value.
Methods of HashMap:
Some of the important methods in HashMap
put(k, v): this method is used to associates the specified
value with the specified key in this map. If the map previously contained a
mapping for the key, the old value is replaced.
clear(): this method is used to removes all of the mappings
from this map. The map will be empty after this call returns.
Remove(): this method is used to removes the mapping for the
specified key from this map if present.
keySet(): this method returns the Set view containing all the keys.
get(Object key): this method returns the object that
contains the value associated with the key.
No comments:
Post a Comment