{"id":3374,"date":"2020-11-02T07:42:51","date_gmt":"2020-11-02T02:12:51","guid":{"rendered":"https:\/\/www.scientecheasy.com\/?p=3374"},"modified":"2025-05-16T17:26:08","modified_gmt":"2025-05-16T11:56:08","slug":"hashmap-in-java","status":"publish","type":"post","link":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/","title":{"rendered":"HashMap in Java"},"content":{"rendered":"<p><strong>HashMap in Java<\/strong> is an unordered collection that stores elements (objects) in the form of key-value pairs (called entries).<\/p>\n<p>It is expressed as HashMap&lt;Key, Value&gt;, or HashMap&lt;K, V&gt;, where K stands for key and V for value. Both Key and value are objects. HashMap uses an object to retrieve another object.<\/p>\n<p>If the key is provided, its associated value can be easily retrieved from the HashMap. Keys in the map must be unique which means we cannot use duplicate data for keys in the HashMap. If we try to insert an entry that has a duplicate key, the map replaces the old entry with a new entry.<\/p>\n<p>Java HashMap class is one of four concrete implementations of the <a href=\"\/2020\/10\/map-in-java.html\/\">Map interface<\/a>. It was added in Java 1.2 version and found in Java. util.HashMap&lt;K, V&gt; package. It is efficient for locating a value, adding an entry, and deleting an entry.<\/p>\n<h2>Hierarchy of HashMap Class in Java<\/h2>\n<hr \/>\n<p>HashMap class in Java extends AbstractMap class and implements the Map interface. The hierarchy diagram of HashMap can be seen in the below figure.<\/p>\n<p><a href=\" https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3379 size-full\" src=\"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2020\/11\/HashSet-_Interface_.png\" alt=\"Java HashMap hierarchy diagram\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2020\/11\/HashSet-_Interface_.png 600w, https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2020\/11\/HashSet-_Interface_-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h2>HashMap Class Declaration<\/h2>\n<hr \/>\n<p>HashMap is a generic class that can be declared as follows:<\/p>\n<pre><code class=\"language-java\">public class HashMap&lt;K,V&gt;\r\n   extends AbstractMap&lt;K,V&gt;\r\n   implements Map&lt;K,V&gt;, Cloneable, Serializable<\/code><\/pre>\n<p>[blocksy-content-block id=&#8221;12371&#8243;]<\/p>\n<h2>Features of Java HashMap Class<\/h2>\n<hr \/>\n<p>There are several important features of HashMap class that you need to keep in mind. They are as:<\/p>\n<p>1. The underlying data structure of HashMap is <a href=\"\/2020\/12\/hashtable-in-java.html\/\">HashTable<\/a>. In simple words, HashMap internally uses hash table for storing entries. That means accessing and adding an entry almost as fast as accessing an array.<\/p>\n<p>2. In HashMap, insertion order is not preserved (i.e. maintains no order). Which means we cannot retrieve keys and values in the same order in which they have been inserted into the HashMap.<\/p>\n<p>3. It is based on the Hashcode of keys, not on the hash code of values.<\/p>\n<p>4. Java HashMap contains only unique keys that means no duplicate keys are allowed but values can be duplicated. We retrieve values based on the key.<\/p>\n<p>5. Heterogeneous objects are allowed for both keys and values.<\/p>\n<p>6. Java HashMap can have only one null key because duplicate keys are not allowed.<\/p>\n<p>7. Multiple null values are allowed in the HashMap.<\/p>\n<p>8. HashMap in Java is not synchronized that means while using multiple threads on the HashMap object, we will get unreliable results.<\/p>\n<p>9. Java HashMap implements Cloneable, and Serializable interfaces but not implements Random Access.<\/p>\n<p>10. HashMap is the best choice if our frequent operation is a search operation.<\/p>\n<p>11. If no element exists in the HashMap, it will throw an <a href=\"\/2020\/08\/exception-handling-in-java.html\/\">exception<\/a> named NoSuchElementException.<\/p>\n<p>12. Java HashMap stores only object references. Therefore, we cannot use primitive data types like double or int. We can use wrapper class like Integer or Double instead.<br \/>\n[blocksy-content-block id=&#8221;12121&#8243;]<\/p>\n<h2>Constructors of HashMap Class<\/h2>\n<hr \/>\n<p>HashMap class in Java provides four constructors that are as follows:<\/p>\n<p><strong>1. <span style=\"color: #0000ff;\">HashMap():<\/span><\/strong><\/p>\n<p>This constructor is used to construct an empty HashMap object with the default initial capacity of 16 and the default fill ratio (load factor) is 0.75. The syntax to create a hash map object is as follows:<\/p>\n<pre><code class=\"language-java\">HashMap hmap = new HashMap();\r\nHashMap&lt;K, V&gt; hmap = new HashMap&lt;K,V&gt;(); \/\/ Generic form.<\/code><\/pre>\n<p><strong>2. <span style=\"color: #0000ff;\">HashMap(int initialCapacity):<\/span><\/strong><\/p>\n<p>This form of constructor is used to create an empty hash map object with a specified initial capacity under the default load factor 0.75. The general syntax is as follows:<\/p>\n<pre><code class=\"language-java\">HashMap&lt;K,V&gt; hmap = new HashMap&lt;K,V&gt;(int initialCapacity);<\/code><\/pre>\n<p><strong>3. <span style=\"color: #0000ff;\">HashMap(Map m):<\/span><\/strong><\/p>\n<p>This constructor is used to create hash map object by initializing the elements of the given Map object m.<\/p>\n<p><strong>4. <span style=\"color: #0000ff;\">HashMap(int initialCapacity, float loadFactor):<\/span><\/strong><\/p>\n<p>This constructor is used to create hash map object with specified initial capacity and load factor. The general syntax to create hash map object with initial capacity and load factor is as:<\/p>\n<pre><code class=\"language-java\">HashMap&lt;K,V&gt; hmap = new HashMap&lt;&gt;(int initialCapacity, float loadFactor);\r\n\r\nFor example:\r\n      HashMap&lt;String, Integer&gt; hmap = new HashMap&lt;&gt;(30, 0.7f);<\/code><\/pre>\n<p>In the above syntax, capacity is the number of buckets in which hash map values can be stored. The load factor is the amount of buckets that are used before the capacity automatically is grown.<\/p>\n<p>The value is a floating-point number that has ranges from 0 (empty) to 1.0 (full). 0.7 means when buckets are 70% full, the capacity is increased. The default capacity is 16 and the load factor is 0.75 that is often sufficient.<\/p>\n<h2>HashMap Methods in Java<\/h2>\n<hr \/>\n<p>In this section, we have listed several important methods available in HashMap class that are as follows:<\/p>\n<p>1. <strong>void clear():<\/strong> It is used to remove entries from the specified map.<\/p>\n<p>2. <strong>boolean isEmpty():<\/strong> This method is used to check whether the map is empty or not. If there are no key-value mapping present in the hash map then it returns true, else false.<\/p>\n<p>3. <strong>Object clone():<\/strong> It is used to create a shallow copy of this HashMap. Only hashmap and all entries are cloned, not elements. Both this map and new map share references to the same keys and values.<\/p>\n<p>4. <strong>Set entrySet():<\/strong> It is used to return a set view containing all of the key\/value pairs in this map.<\/p>\n<p>5. <strong>Set keySet():<\/strong> This method is used to retrieve a set view of the keys in this map.<br \/>\n[blocksy-content-block id=&#8221;12153&#8243;]<\/p>\n<p>6. <strong>V put(Object key, Object value):<\/strong> This method is used to insert an entry in the map.<\/p>\n<p>7. <strong>void putAll(Map map):<\/strong> This method is used to insert all the entries of the specified map to another map.<\/p>\n<p>8. <strong>V putIfAbsent(K key, V value):<\/strong> This method adds the specified value associated with the specified key in the map only if it is not already specified.<\/p>\n<p>9. <strong>V remove(Object key):<\/strong> This method is used to delete an entry for the specified key.<\/p>\n<p>10. <strong>boolean remove(Object key, Object value):<\/strong> This method removes the specified value associated with specific key from the map.<\/p>\n<hr \/>\n<p>11. <strong>int size():<\/strong> This method returns the number of entries in the map.<\/p>\n<p>12. <strong>Collection values():<\/strong> This method returns a collection view containing all of the values in the map.<\/p>\n<p>13. <strong>V get(Object key):<\/strong> This method is used to retrieve the value associated with a key. Its return type is Object.<\/p>\n<p>14. <strong>V replace(K key, V value):<\/strong> This method is used to replace the specified value for a specified key.<\/p>\n<p>15. <strong>boolean replace(K key, V oldValue, V newValue):<\/strong> This method is used to replace the old value with the new value for a specified key.<\/p>\n<hr \/>\n<p>16. <strong>boolean containsValue(Object v):<\/strong> This method is used to determine if map contains a particular value. It returns true if some value is equal to the v.<\/p>\n<p>17. <strong>boolean containsKey(Object k):<\/strong> This method is used to determine if the map contains a particular key. It will return true if some key in this map is equal to k.<\/p>\n<p>18. <strong>boolean equals(Object o):<\/strong> This method is used to compare the specified Object with the Map.<\/p>\n<h2>Java HashMap Examples<\/h2>\n<hr \/>\n<h3><strong>1. Adding Entries<\/strong><\/h3>\n<p><strong>Example 1:<\/strong> Let&#8217;s write a Java program where we will simply add entries in the HashMap and display it on the console.<\/p>\n<pre><code class=\"language-java\">import java.util.HashMap;\r\npublic class HashMapEx1 {\r\npublic static void main(String[] args) \r\n{\r\n\/\/ Create a HashMap.\t\r\n   HashMap&lt;String,Integer&gt; hmap = new HashMap&lt;&gt;();\r\n \r\n\/\/ Checking HashMap is empty or not.\r\n   boolean empty = hmap.isEmpty();\r\n   System.out.println(\"Is HashMap empty: \" +empty);\r\n \r\n\/\/ Adding entries in the hash map.\r\n   hmap.put(\"John\", 24); \/\/ hmap.size() is 1.\r\n   hmap.put(\"Deep\", 22); \/\/ hmap.size() is 2.\r\n   hmap.put(\"Shubh\", 15); \/\/ hmap.size() is 3.\r\n   hmap.put(\"Riky\", 22); \/\/ hmap.size() is 4. \/\/ Adding duplicate value.\r\n   hmap.put(\"Mark\", 30); \/\/ hmap.size() is 5.\r\n   \r\n   System.out.println(\"Entries in HashMap: \" +hmap);  \r\n   int size = hmap.size();\r\n   System.out.println(\"Size of HashMap: \" +size);\r\n\r\n\/\/ Adding null key and value.\r\n   hmap.put(null, null); \/\/ hmap.size() is 6.\r\n   System.out.println(\"Updated entries in HashMap: \" +hmap);\r\n   }\r\n}<\/code><\/pre>\n<pre>Output:\r\n      Is HashMap empty: true\r\n      Entries in HashMap: {Riky=22, Shubh=15, John=24, Mark=30, Deep=22}\r\n      Size of HashMap: 5\r\n      Updated entries in HashMap: {null=null, Riky=22, Shubh=15, John=24, Mark=30, Deep=22}\r\n<\/pre>\n<p>As you can see from the above output, the entries in the HashMap are in no particular order in which they are inserted in map. We have stored String as keys, and Integer as values as so we are using HashMap&lt;String, Integer&gt; as the type. The put() method adds the entries to the map.<\/p>\n<hr \/>\n<h3>2. Adding Duplicate Keys and Values<\/h3>\n<p><strong>Example 2:<\/strong> Let&#8217;s write a Java program in which we will try to add duplicate keys and values in HashMap.<\/p>\n<pre><code class=\"language-java\">import java.util.HashMap;\r\npublic class HashMapEx2 {\r\npublic static void main(String[] args) \r\n{\t\r\n  HashMap&lt;Integer, String&gt; hmap = new HashMap&lt;&gt;();\r\n  hmap.put(5, \"Banana\");\r\n  hmap.put(10, \"Mango\");\r\n  hmap.put(15, \"Apple\");\r\n\r\n  System.out.println(\"Entries in HashMap: \" +hmap);  \r\n  System.out.println(\"Size of HashMap: \" +hmap.size());\r\n\r\n\/\/ Adding duplicate key in hash map.\r\n   hmap.put(10, \"Guava\"); \/\/ Still hmap.size is 3.\r\n   hmap.put(20, \"Banana\"); \/\/ Adding duplicate value.\r\n   \r\n   System.out.println(\"Updated entries in HashMap: \" +hmap);\r\n   System.out.println(\"Size after adding duplicate value: \" +hmap.size());\r\n   }\r\n}<\/code><\/pre>\n<pre>Output:\r\n      Entries in HashMap: {5=Banana, 10=Mango, 15=Apple}\r\n      Size of HashMap: 3\r\n      Updated entries in HashMap: {20=Banana, 5=Banana, 10=Guava, 15=Apple}\r\n      Size after adding duplicate value: 4\r\n<\/pre>\n<p>As you can see in this program, we cannot store duplicate keys in HashMap. However, we have tried to store a duplicate key with another value, but it simply replaced the value.<\/p>\n<hr \/>\n<h3>3. Remove Entry<\/h3>\n<p><strong>Example 3:<\/strong> Let&#8217;s write a Java program where we will perform the remove operation. We will remove entry from the HashMap using remove() method. Look at the example code.<\/p>\n<pre><code class=\"language-java\">import java.util.HashMap;\r\npublic class HashMapEx3 {\r\npublic static void main(String[] args) \r\n{\t\r\n  HashMap&lt;Character,String&gt; hmap = new HashMap&lt;&gt;();\r\n   \r\n  hmap.put('R', \"Red\");\r\n  hmap.put('O', \"Orange\");\r\n  hmap.put('G', \"Green\");\r\n  hmap.put('B', \"Brown\");\r\n  hmap.put('W', \"White\");\r\n\r\n\/\/ Displaying HashMap entries.  \r\n   System.out.println(\"Entries in HashMap: \" +hmap);\r\n\r\n\/\/ Removing Key-Value pairs for key 'B'. \r\n   Object removeEntry = hmap.remove('B');\r\n   System.out.println(\"Removed Entry: \" +removeEntry);\r\n   System.out.println(\"HashMap Entries after remove: \" +hmap);\r\n  \r\n\/\/ Checking entry is removed or not.  \r\n   Object removeEntry2 = hmap.remove('W', \"White\");\r\n   System.out.println(\"Is entry removed: \" +removeEntry2);\r\n   System.out.println(\"Updated HashMap entries: \" +hmap);\r\n   }\r\n}<\/code><\/pre>\n<pre>Output:\r\n       Entries in HashMap: {R=Red, B=Brown, G=Green, W=White, O=Orange}\r\n       Removed Entry: Brown\r\n       HashMap Entries after remove: {R=Red, G=Green, W=White, O=Orange}\r\n       Is entry removed: true\r\n       Updated HashMap entries: {R=Red, G=Green, O=Orange}<\/pre>\n<h3>4. Replacing Value<\/h3>\n<p><strong>Example 4:<\/strong> Let&#8217;s write a Java program where we will replace a specified value for the specified key. Look at the program code.<\/p>\n<pre><code class=\"language-java\">import java.util.HashMap;\r\npublic class HashMapEx4 {\r\npublic static void main(String[] args) \r\n{\t\r\n  HashMap&lt;Character,String&gt; hmap = new HashMap&lt;&gt;();\r\n   \r\n  hmap.put('R', \"Red\");\r\n  hmap.put('O', \"Orange\");\r\n  hmap.put('G', \"Green\");\r\n  hmap.put('B', \"Brown\");\r\n  hmap.put('W', \"White\");\r\n\r\n\/\/ Displaying HashMap entries.  \r\n   System.out.println(\"Entries in HashMap: \" +hmap);\r\n\r\n\/\/ Replacing specified value for the specified key.  \r\n   Object replaceValue = hmap.replace('B', \"Black\");\r\n   System.out.println(\"Replaced value: \" +replaceValue);\r\n   System.out.println(\"Updated entries in HashMap: \" +hmap);\r\n   \r\n   boolean replaceValue2 = hmap.replace('G', \"Green\", \"Greenish\");\r\n   System.out.println(\"Is value replaced: \" +replaceValue2);\r\n   System.out.println(hmap);\r\n   }\r\n}<\/code><\/pre>\n<pre>Output:\r\n       Entries in HashMap: {R=Red, B=Brown, G=Green, W=White, O=Orange}\r\n       Replaced value: Brown\r\n       Updated entries in HashMap: {R=Red, B=Black, G=Green, W=White, O=Orange}\r\n       Is value replaced: true\r\n       {R=Red, B=Black, G=Greenish, W=White, O=Orange}\r\n<\/pre>\n<h2>Use of HashMap in Java<\/h2>\n<hr \/>\n<p>Java HashMap can be the best choice if we want to perform a search operation. It is designed to rapidly find things. The best example of this kind is phonebook. The name of person (a string) can be used to search the person&#8217;s phone number. Let&#8217;s understand it with a simple example program. Look at the following example code.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-java\">import java.util.HashMap;\r\npublic class HashMapUse {\r\npublic static void main(String[] args) \r\n{\t\r\n  HashMap&lt;String, Long&gt; hmap = new HashMap&lt;&gt;();\r\n   \r\n  hmap.put(\"John\", 9431676282L);\r\n  hmap.put(\"Deep\", 8292736478L);\r\n  hmap.put(\"Shubh\", 8123543268L);\r\n  hmap.put(\"Mark\", 9876789142L);\r\n  hmap.put(\"Ricky\", 8768976872L);\r\n\r\n\/\/ Retrieve number with its key by calling get() method.\r\n   Long number = hmap.get(\"Deep\");\r\n   System.out.println(\"Deep's phone number: \" +number);\r\n   \r\n   Long number2 = hmap.getOrDefault(\"Steave\", -1L);\r\n   System.out.println(\"Alex's phone number: \" +number2);\r\n   }\r\n}<\/code><\/pre>\n<pre>Output:\r\n      Deep's phone number: 8292736478\r\n      Alex's phone number: -1\r\n<\/pre>\n<p>In this example, we have created a HashMap called phonebook with keys (person&#8217;s name) that are strings and values (person&#8217;s phone number) that are Long objects. Objects are stored in the hash map by calling put(Object key, Object value) method.<\/p>\n<p>This method stores an item on the map with key as name and value as a phone number. hmap.put(&#8220;John&#8221;, 9431676282L);. If the specified key is not found, -1 is returned by default.<\/p>\n<hr \/>\n<p>In this tutorial, we have discussed Java HashMap with the help of example programs. Hope that you will have understood the basic key features of HashMap and practiced all programs based on the HashMap methods.<br \/>\nThanks for reading!!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HashMap in Java is an unordered collection that stores elements (objects) in the form of key-value pairs (called entries). It is expressed as HashMap&lt;Key, Value&gt;, or HashMap&lt;K, V&gt;, where K stands for key and V for value. Both Key and value are objects. HashMap uses an object to retrieve another object. If the key is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3377,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_gspb_post_css":"","footnotes":""},"categories":[2],"tags":[182,183,184],"class_list":["post-3374","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-hashmap-methods-in-java","tag-java-hashmap","tag-use-of-hashmap"],"blocksy_meta":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>HashMap in Java - Scientech Easy<\/title>\n<meta name=\"description\" content=\"Learn HashMap in Java with example program, Java HashMap class methods, constructors, use of HashMap, hierarchy, adding and removing entries\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HashMap in Java - Scientech Easy\" \/>\n<meta property=\"og:description\" content=\"Learn HashMap in Java with example program, Java HashMap class methods, constructors, use of HashMap, hierarchy, adding and removing entries\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/\" \/>\n<meta property=\"og:site_name\" content=\"Scientech Easy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/scientecheasy\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/D.gupta008\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-02T02:12:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-16T11:56:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2020\/11\/java-hashmap-hierarchy.png\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"DEEPAK GUPTA\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DEEPAK GUPTA\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/\"},\"author\":{\"name\":\"DEEPAK GUPTA\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/#\\\/schema\\\/person\\\/b5bb668584010e27bf869ba72f0fd7f2\"},\"headline\":\"HashMap in Java\",\"datePublished\":\"2020-11-02T02:12:51+00:00\",\"dateModified\":\"2025-05-16T11:56:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/\"},\"wordCount\":1452,\"publisher\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scientecheasy.com\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/java-hashmap-hierarchy.png\",\"keywords\":[\"HashMap methods in Java\",\"Java Hashmap\",\"Use of HashMap\"],\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/\",\"url\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/\",\"name\":\"HashMap in Java - Scientech Easy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scientecheasy.com\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/java-hashmap-hierarchy.png\",\"datePublished\":\"2020-11-02T02:12:51+00:00\",\"dateModified\":\"2025-05-16T11:56:08+00:00\",\"description\":\"Learn HashMap in Java with example program, Java HashMap class methods, constructors, use of HashMap, hierarchy, adding and removing entries\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.scientecheasy.com\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/java-hashmap-hierarchy.png\",\"contentUrl\":\"https:\\\/\\\/www.scientecheasy.com\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/java-hashmap-hierarchy.png\",\"width\":600,\"height\":400,\"caption\":\"Java HashMap hierarchy diagram\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/2020\\\/11\\\/hashmap-in-java.html\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scientecheasy.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HashMap in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/#website\",\"url\":\"https:\\\/\\\/www.scientecheasy.com\\\/\",\"name\":\"Scientech Easy\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scientecheasy.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/#organization\",\"name\":\"Scientech Easy\",\"url\":\"https:\\\/\\\/www.scientecheasy.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.scientecheasy.com\\\/wp-content\\\/uploads\\\/2024\\\/06\\\/scientecheasy-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.scientecheasy.com\\\/wp-content\\\/uploads\\\/2024\\\/06\\\/scientecheasy-logo.png\",\"width\":119,\"height\":119,\"caption\":\"Scientech Easy\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/scientecheasy\\\/\",\"https:\\\/\\\/medium.com\\\/scientech-easy\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/#\\\/schema\\\/person\\\/b5bb668584010e27bf869ba72f0fd7f2\",\"name\":\"DEEPAK GUPTA\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scientecheasy.com\\\/wp-content\\\/litespeed\\\/avatar\\\/a4855f82604819e190e1d130415225c7.jpg?ver=1778108696\",\"url\":\"https:\\\/\\\/www.scientecheasy.com\\\/wp-content\\\/litespeed\\\/avatar\\\/a4855f82604819e190e1d130415225c7.jpg?ver=1778108696\",\"contentUrl\":\"https:\\\/\\\/www.scientecheasy.com\\\/wp-content\\\/litespeed\\\/avatar\\\/a4855f82604819e190e1d130415225c7.jpg?ver=1778108696\",\"caption\":\"DEEPAK GUPTA\"},\"description\":\"Deepak Gupta is the Founder of Scientech Easy, a Full Stack Developer, and a passionate coding educator with 8+ years of professional experience in Java, Python, web development, and core computer science subjects. With strong expertise in full-stack development, he provides hands-on training in programming languages and in-demand technologies at the Scientech Easy Institute, Dhanbad. He regularly publishes in-depth tutorials, practical coding examples, and high-quality learning resources for both beginners and working professionals. Every article is carefully researched, technically reviewed, and regularly updated to ensure accuracy, clarity, and real-world relevance, helping learners build job-ready skills with confidence.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/D.gupta008\",\"https:\\\/\\\/www.instagram.com\\\/deepak_scientecheasy\\\/\",\"www.linkedin.com\\\/in\\\/deepak-kumar-gupta-41993414a\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HashMap in Java - Scientech Easy","description":"Learn HashMap in Java with example program, Java HashMap class methods, constructors, use of HashMap, hierarchy, adding and removing entries","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/","og_locale":"en_US","og_type":"article","og_title":"HashMap in Java - Scientech Easy","og_description":"Learn HashMap in Java with example program, Java HashMap class methods, constructors, use of HashMap, hierarchy, adding and removing entries","og_url":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/","og_site_name":"Scientech Easy","article_publisher":"https:\/\/www.facebook.com\/scientecheasy\/","article_author":"https:\/\/www.facebook.com\/D.gupta008","article_published_time":"2020-11-02T02:12:51+00:00","article_modified_time":"2025-05-16T11:56:08+00:00","og_image":[{"width":600,"height":400,"url":"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2020\/11\/java-hashmap-hierarchy.png","type":"image\/png"}],"author":"DEEPAK GUPTA","twitter_card":"summary_large_image","twitter_misc":{"Written by":"DEEPAK GUPTA","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/#article","isPartOf":{"@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/"},"author":{"name":"DEEPAK GUPTA","@id":"https:\/\/www.scientecheasy.com\/#\/schema\/person\/b5bb668584010e27bf869ba72f0fd7f2"},"headline":"HashMap in Java","datePublished":"2020-11-02T02:12:51+00:00","dateModified":"2025-05-16T11:56:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/"},"wordCount":1452,"publisher":{"@id":"https:\/\/www.scientecheasy.com\/#organization"},"image":{"@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2020\/11\/java-hashmap-hierarchy.png","keywords":["HashMap methods in Java","Java Hashmap","Use of HashMap"],"articleSection":["Java"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/","url":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/","name":"HashMap in Java - Scientech Easy","isPartOf":{"@id":"https:\/\/www.scientecheasy.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/#primaryimage"},"image":{"@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2020\/11\/java-hashmap-hierarchy.png","datePublished":"2020-11-02T02:12:51+00:00","dateModified":"2025-05-16T11:56:08+00:00","description":"Learn HashMap in Java with example program, Java HashMap class methods, constructors, use of HashMap, hierarchy, adding and removing entries","breadcrumb":{"@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/#primaryimage","url":"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2020\/11\/java-hashmap-hierarchy.png","contentUrl":"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2020\/11\/java-hashmap-hierarchy.png","width":600,"height":400,"caption":"Java HashMap hierarchy diagram"},{"@type":"BreadcrumbList","@id":"https:\/\/www.scientecheasy.com\/2020\/11\/hashmap-in-java.html\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scientecheasy.com\/"},{"@type":"ListItem","position":2,"name":"HashMap in Java"}]},{"@type":"WebSite","@id":"https:\/\/www.scientecheasy.com\/#website","url":"https:\/\/www.scientecheasy.com\/","name":"Scientech Easy","description":"","publisher":{"@id":"https:\/\/www.scientecheasy.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scientecheasy.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.scientecheasy.com\/#organization","name":"Scientech Easy","url":"https:\/\/www.scientecheasy.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scientecheasy.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2024\/06\/scientecheasy-logo.png","contentUrl":"https:\/\/www.scientecheasy.com\/wp-content\/uploads\/2024\/06\/scientecheasy-logo.png","width":119,"height":119,"caption":"Scientech Easy"},"image":{"@id":"https:\/\/www.scientecheasy.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/scientecheasy\/","https:\/\/medium.com\/scientech-easy"]},{"@type":"Person","@id":"https:\/\/www.scientecheasy.com\/#\/schema\/person\/b5bb668584010e27bf869ba72f0fd7f2","name":"DEEPAK GUPTA","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scientecheasy.com\/wp-content\/litespeed\/avatar\/a4855f82604819e190e1d130415225c7.jpg?ver=1778108696","url":"https:\/\/www.scientecheasy.com\/wp-content\/litespeed\/avatar\/a4855f82604819e190e1d130415225c7.jpg?ver=1778108696","contentUrl":"https:\/\/www.scientecheasy.com\/wp-content\/litespeed\/avatar\/a4855f82604819e190e1d130415225c7.jpg?ver=1778108696","caption":"DEEPAK GUPTA"},"description":"Deepak Gupta is the Founder of Scientech Easy, a Full Stack Developer, and a passionate coding educator with 8+ years of professional experience in Java, Python, web development, and core computer science subjects. With strong expertise in full-stack development, he provides hands-on training in programming languages and in-demand technologies at the Scientech Easy Institute, Dhanbad. He regularly publishes in-depth tutorials, practical coding examples, and high-quality learning resources for both beginners and working professionals. Every article is carefully researched, technically reviewed, and regularly updated to ensure accuracy, clarity, and real-world relevance, helping learners build job-ready skills with confidence.","sameAs":["https:\/\/www.facebook.com\/D.gupta008","https:\/\/www.instagram.com\/deepak_scientecheasy\/","www.linkedin.com\/in\/deepak-kumar-gupta-41993414a"]}]}},"_links":{"self":[{"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/posts\/3374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/comments?post=3374"}],"version-history":[{"count":0,"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/posts\/3374\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/media\/3377"}],"wp:attachment":[{"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/media?parent=3374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/categories?post=3374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scientecheasy.com\/wp-json\/wp\/v2\/tags?post=3374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}