What is HashMap in Java — Explained with examples.


  1. What is HashMap in Java?
  2. Initialization of HashMap in Java
  3. Hierarchy of HashMap
  4. Internal Structure of HashMap
  5. Basic Operations of HashMap — Adding Elements, Changing Elements, Removing Elements, Iterating over HashMap
  6. Different methods of HashMap
  7. Factors affecting the performance of HashMap — Initial Capacity, Load Factor, Threshold
  8. Types of Constructors in HashMap
  9. Sorting in HashMap
  10. Summarizing
  11. Conclusion

What is HashMap in Java?

As told above, it is a type of Data Structure that is used to store data in the form of key and value pairs where both key and value are initialized using object/wrapper classes of the primitive data types like Integer, Boolean, String — which is already a wrapper class.

Initialization of HashMap in Java

To use a HashMap in our Java Program, we first have to import it from java.util package, and then use the below syntax to initialize it in the program

HashMap<K, V> numbers = new HashMap<K, V>();
HashMap<String, Integer> numbers = new HashMap<String Integer>();



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store