Java HashMap

Posted in Java, Java Collections By Raj On November 18, 2017


In my previous article, I have explained about Map Interface, in this article, I am going to explain about HashMap, the HashMap uses hash table algorithm to store the entry, the problem with this is, you will not retrieve same order whatever you have inserted

The HashMap implements Map Interface so, you can have duplicate key’s but having duplicate key will not throw any compile time or runtime error, instead of that the old value will be replaced with new value

The below things you need to consider before choosing HashMap

  • The HashMap does not support duplicate values
  • You will not get same order whatever you have stored
  • The initial capacity for HashMap is 16
  • The HashMap allows null values 

The HashMap extends AbstractMap and implements the Map interface

Java HashMap


The following program explains how HashMap works 

OutPut :

If you are looking more examples on HashMap then I would recommend you check this Java Code Snippets: HashMap