HashMap is one of the most widely used data structures in Java Collection. Insertion and Retrieval are the most frequently used operations, and HashMap execute these processes in constant time, no matter how big the data is. It stores key-value pairs and to access a value, one must know it's key.
Features of HashMap:
- It is present in java.util package.
- Keys are stored with Hashing technique.
- Duplicate Keys are not allowed, but more than one key can contain the same object.
- Ordered arrangement of Keys is not guaranteed.
Declaring a hashmap:
HashMap map = new HashMap<>();
Adding Items to the hashmap:
map.put("Key1", 10);
map.put("key2", 20);
Searching Items in the hashmap with key:
Integer i = map.get("key2");
System.out.println("Value is : "+i);
Deleting Items:
remove("key1");