

{"id":21534,"date":"2018-07-17T04:00:56","date_gmt":"2018-07-17T04:00:56","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=21534"},"modified":"2026-05-22T17:36:50","modified_gmt":"2026-05-22T12:06:50","slug":"java-hashmap","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/java-hashmap\/","title":{"rendered":"Java HashMap | Constructors &amp; Methods of HashMap in Java"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1878,&quot;href&quot;:&quot;https:\\\/\\\/docs.oracle.com&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251210062804\\\/https:\\\/\\\/docs.oracle.com\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-15 06:26:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 05:00:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-22 00:46:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 17:56:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-24 21:46:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-28 01:31:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-05 08:06:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-11 00:55:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-14 19:50:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-03 17:08:04&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-03 17:08:04&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p><span style=\"font-weight: 400\">Today, in this<strong><a href=\"https:\/\/data-flair.training\/blogs\/java-tutorial\/\" target=\"_blank\" rel=\"noopener\"> Java <\/a><\/strong>HashMap tutorial, we are going to learn about the HashMap in Java. First, we will start with the meaning of Java HashMap. Moreover, we will learn about constructors and methods in HashMap in Java. Also, we will discuss the Java HashMap example and the internal structure of HashMap in Java.<\/span><\/p>\n<p><span style=\"font-weight: 400\">So, let us start the Java HashMap Tutorial.<\/span><\/p>\n<div id=\"attachment_21599\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-21599\" class=\"wp-image-21599 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01.jpg\" alt=\"Java HashMap\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-21599\" class=\"wp-caption-text\">Java HashMap | Constructors &amp; Methods of HashMap in Java<\/p><\/div>\n<h3>What is a Java HashMap?<\/h3>\n<p><span style=\"font-weight: 400\">Java HashMap permits null keys and null values.<\/span><\/p>\n<p><span style=\"font-weight: 400\">HashMap isn&#8217;t an ordered collection. You\u2019ll be able to iterate over HashMap entries through the keys set; however, they&#8217;re not guaranteed to be in the order of their addition to the HashMap.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/inheritance-in-java\/\" target=\"_blank\" rel=\"noopener\">Do you know What is Inheritance in Java?<\/a><\/strong><\/p>\n<p><span style=\"font-weight: 400\">HashMap in Java uses its inner category Node for storing map entries.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Java HashMap stores entries into multiple one-by-one linked lists, which are called buckets or bins. The default range of bins is 16, and it\u2019s always a power of 2.<\/span><\/p>\n<p><span style=\"font-weight: 400\">HashMap uses hashCode() and equals() methods on keys to get and place operations. Therefore, the HashMap key object should offer a good implementation of those ways. This can be the reason immutable classes are more suitable for keys, for example, String and Integer.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Java HashMap isn&#8217;t thread-safe; for a multithreaded environment, you must use the ConcurrentHashMap category or get a synchronous map using the Collections.synchronizedMap() method.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/method-overriding-in-java\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s discuss Methos Overriding in Java<\/a><\/strong><\/p>\n<h3>Java HashMap Constructors<\/h3>\n<p><span style=\"font-weight: 400\">HashMap in Java provides four constructors. So, below we are discussing 4 constructors in the Java HashMap tutorial:<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>1. public HashMap():<\/strong>\u00a0Most commonly used HashMap constructor. This constructor can produce an empty HashMap with default initial capacity 16 and load factor 0.75<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>2. public HashMap(int initialCapacity):<\/strong> This HashMap constructor is used to specify the initial capacity and 0.75 ratio. This can helps in avoiding rehashing if you know the number of mappings to hold in the HashMap.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>3. public HashMap(int initialCapacity, float loadFactor):<\/strong> This HashMap constructor can produce an empty HashMap with specified initial capacity and load factor. <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>4. public HashMap(Map&lt;? extends K, ? extends V&gt; m):<\/strong> Creates a Map having the same mappings as the specified map and with a load factor of 0.75<\/span><br \/>\n<span style=\"font-weight: 400\">Example of Java HashMap Constructors<\/span><\/p>\n<p><span style=\"font-weight: 400\">The code snippet is showing the constructor of HashMap in Java, exemplifying all the above constructors.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/java-file-class\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s learn Java File Class<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">Map map1 = new HashMap&lt;&gt;();\r\nMap map2 = new HashMap&lt;&gt;(2^5);\r\nMap map3 = new HashMap&lt;&gt;(32,0.80f);\r\nMap map4 = new HashMap&lt;&gt;(map1);<\/pre>\n<h3>Methods of HashMap in Java<\/h3>\n<h4>Important methods of Java HashMap<\/h4>\n<p><span style=\"font-weight: 400\">Let\u2019s have a look at the important methods of Java HashMap:<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>1. public void clear():<\/strong> This Java HashMap method will remove all the mappings, and the HashMap will become empty.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>2. public boolean containsKey(Object key):<\/strong> This HashMap in Java method returns \u2018true\u2019 if the key exists, otherwise it will return \u2018false\u2019.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>3. public mathematician containsValue(Object value):<\/strong> This Java HashMap method returns true if the value exists.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>4. public Set&gt; entrySet():<\/strong> This HashMap method in Java returns a set view of the HashMap mappings. <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>5. public V get(Object key): <\/strong>This Java HashMap method returns the value mapped to the specified key, or null if there&#8217;s no mapping for the key.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>6. public boolean isEmpty():<\/strong> A utility method returning true if no key-value mappings are present.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/interface-in-java\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s see Java Interface<\/a><\/strong><\/p>\n<p><span style=\"font-weight: 400\"><strong>7. public Set keySet():<\/strong> Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected within the set, and vice versa.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>8. public V put(K key, V value):<\/strong> This method associates the specified value with the specified key in this map, and if the map previously contained a mapping for the key, the old value is replaced.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>9. public void putAll(Map&lt;? extends K, ? extends V&gt; m):<\/strong> Copies all of the mappings from the required map to the present map. Therefore, These mappings can replace any mappings that this map had for any of the keys currently within the specified map.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>10. public V remove(Object key):<\/strong> This Java HashMap method helps remove the mapping for the required key from this map if present.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>11. public int size():<\/strong> This method in HashMap in Java helps return the number of key-value mappings in this map.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>12. public Collection values():<\/strong> This method of HashMap in Java helps return a collection view of the values contained in this map. Although the collection is backed by the map, changes to the map are reflected in the collection, and vice versa.<\/span><\/p>\n<h4>New Methods of Java HashMap<\/h4>\n<p><span style=\"font-weight: 400\">Many<strong> new methods in Java HashMap<\/strong> were introduced in Java 8, let us have a look at them &#8211;<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>1. public V computeIfAbsent(K key, Function&lt;? super K, ? extends V&gt; mappingFunction):<\/strong> If the specified key is not already associated with a value (or is mapped to null), however, this method tries to compute its value using the given mapping function and therefore enters it into the HashMap unless it is Null.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>2. public V computeIfPresent(K key, BiFunction&lt;? super K, ? super V, ? extends V&gt; remappingFunction):<\/strong> In this method, if the value for the required key is present and non-null, it, therefore, tries to reason a replacement mapping given the key and its current mapped value.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/packages-in-java\/\" target=\"_blank\" rel=\"noopener\">Read Java Packages<\/a><\/strong><\/p>\n<p><span style=\"font-weight: 400\"><strong>3. public V compute(K key, BiFunction&lt;? super K, ? super V, ? extends V&gt; remappingFunction):<\/strong> This HashMap method attempts to compute a mapping for the required key and its current mapped value.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>4. public void forEach(BiConsumer&lt;? super K, ? super V&gt; action):<\/strong> This method performs the given action for each entry in this map.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>5. public V getOrDefault(Object key, V defaultValue):<\/strong> Same as get except that defaultValue is returned if no mapping is found for the specified key.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>6. public V merge(K key, V value, BiFunction&lt;? super V, ? super V, ? extends V&gt; remappingFunction):<\/strong> If the required key is not already related to a value or is associated with null, associates it with the given non-null value. <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>7. public V putIfAbsent(K key, V value):<\/strong> In this method, if the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns this price.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>8. public boolean remove(Object key, Object value):<\/strong> This removes the entry for the specified key only if it&#8217;s currently mapped to the specified value.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>9. public boolean replace(K key, V oldValue, V newValue):<\/strong> RIN This method it helps to replace the entry for the specified key only if currently mapped to the specified value.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>10. public V replace(K key, V value):<\/strong> In this method, it helps to replace the entry for the specified key only if it currently maps to some value.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/serialization-and-deserialization-in-java\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s explore Java SerDe<\/a><\/strong><\/p>\n<p><span style=\"font-weight: 400\"><strong>11. public void replaceAll(BiFunction&lt;? super K, ? super V, ? extends V&gt; function):<\/strong> In this method, it helps replace every entry\u2019s value with the result of invoking the given function on that entry.<\/span><\/p>\n<h3>Java HashMap &#8211; Internal Structure<\/h3>\n<p><span style=\"font-weight: 400\">The internal structure of Java HashMap contains these four nodes of the array, and further, each node is represented with the help of a class.<\/span><\/p>\n<ul>\n<li><strong>int hash:<\/strong> it contains the integer type value. However, it keeps the hash code of the key. Hash code contains an address where the object is stored.<\/li>\n<li><strong>K key:<\/strong> Just like the variables are the identifiers, Keys also act as identifiers for the values. Although it allows the null value to be added, the key must be different.<\/li>\n<li><strong>V value:<\/strong> The value is the element or data stored in it.<\/li>\n<li><strong>Node next:<\/strong> It refers to the next block where the value is kept.<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">A node contains a reference to its own object, and hence it is a linked list.<\/span><\/p>\n<div id=\"attachment_21600\" style=\"width: 197px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/array.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-21600\" class=\"wp-image-21600 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/array.png\" alt=\"Java Hashmap - Internal Structures\" width=\"187\" height=\"58\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/array.png 187w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/array-150x47.png 150w\" sizes=\"auto, (max-width: 187px) 100vw, 187px\" \/><\/a><p id=\"caption-attachment-21600\" class=\"wp-caption-text\">Hashmap in Java &#8211; Internal Structures<\/p><\/div>\n<p><strong>Node<\/strong><\/p>\n<div id=\"attachment_21601\" style=\"width: 492px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/c4.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-21601\" class=\"wp-image-21601 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/c4.jpg\" alt=\"Java HashMap\" width=\"482\" height=\"302\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/c4.jpg 482w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/c4-150x94.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/c4-300x188.jpg 300w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/a><p id=\"caption-attachment-21601\" class=\"wp-caption-text\">HashMap in Java<\/p><\/div>\n<h3>Performance of HashMap in Java<\/h3>\n<p><span style=\"font-weight: 400\">Performance of Java HashMap depends on these two factors \u2013<\/span><\/p>\n<p><strong>i. Initial Capacity<\/strong><\/p>\n<p><strong>ii. Load Factor<\/strong><\/p>\n<p><span style=\"font-weight: 400\">In a Java HashMap, the capacity is simply defined as the number of buckets, while the Initial capacity of a HashMap in Java defines when it is created initially. Further, we multiply capacity by 2. <\/span><\/p>\n<p><span style=\"font-weight: 400\">In a\u00a0<strong style=\"font-weight: 400\">Load Factor<\/strong>, a measure of how much rehashing is to be done. Therefore, it is also a measure of how much rehashing to do. It is initially kept higher so rehashing doesn\u2019t take place, but this also increases the iteration time. The most common load factor value is 0.75. It varies from 0 to 1.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/abstract-class-in-java\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s learn about Abstract Class in Java<\/a><\/strong><\/p>\n<p><span style=\"font-weight: 400\">Example of Java HashMap performance\u2013<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import java.util.HashMap;\r\nimport java.util.Map;\r\npublic class DF\r\n{\r\n   public static void main(String[] args)\r\n   {\r\n       HashMap&lt;String, Integer&gt; map = new HashMap&lt;&gt;();\r\n       print(map);\r\n       map.put(\"vishal\", 10);\r\n       map.put(\"sachin\", 30);\r\n       map.put(\"vaibhav\", 20);\r\n       System.out.println(\"Size of map is:- \" + map.size());\r\n       print(map);\r\n       if (map.containsKey(\"vishal\"))\r\n       {\r\n           Integer a = map.get(\"vishal\");\r\n           System.out.println(\"value for key \\\"vishal\\\" is:- \" + a);\r\n       }\r\n       map.clear();\r\n       print(map);\r\n   }\r\n   public static void print(Map&lt;String, Integer&gt; map)\r\n   {\r\n       if (map.isEmpty())\r\n       {\r\n           System.out.println(\"map is empty\");\r\n       }\r\n       else\r\n       {\r\n           System.out.println(map);\r\n       }\r\n   }\r\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\n<span style=\"font-weight: 400\">map is empty<\/span><br \/>\n<span style=\"font-weight: 400\">Size of map is:- 3<\/span><br \/>\n<span style=\"font-weight: 400\">{vaibhav=20, vishal=10, sachin=30}<\/span><br \/>\n<span style=\"font-weight: 400\">value for key &#8220;vishal&#8221; is:- 10<\/span><br \/>\n<span style=\"font-weight: 400\">map is empty<\/span><\/p>\n<p><strong>Read: <a href=\"https:\/\/data-flair.training\/blogs\/linear-data-structures-in-java\/\" target=\"_blank\" rel=\"noopener\">Java Data Structures<\/a><\/strong><\/p>\n<p>So, this was all about the Java HashMap tutorial. Hope you like our explanation of HashMap in Java.<\/p>\n<h3>Common Use Cases for Java HashMaps<\/h3>\n<p>HashMaps are versatile data structures with a wide range of applications in Java programming. Here are some common use cases:<\/p>\n<p><strong>1. Caching:<\/strong> HashMaps are ideal for caching data retrieved from databases or APIs. Thus, by storing frequently accessed data in a HashMap, you can significantly improve application performance by reducing redundant database calls or API requests.<\/p>\n<p><strong>2. Configuration Settings:<\/strong> Applications often rely on configuration settings loaded from files or user input. Therefore, HashMaps provide a convenient way to store and manage these settings using key-value pairs.<\/p>\n<p><strong>3. In-Memory Databases:<\/strong> For small-scale applications or temporary data storage, However, HashMaps can act as simple in-memory databases. They offer fast retrieval and insertion of data based on keys.<\/p>\n<h3>Conclusion<\/h3>\n<p><span style=\"font-weight: 400\">Hence, in this Tutorial, we discussed the complete concept of HashMap in Java. Moreover, we saw the Java HashMap example, the constructor, and its internal structure. Still, if any query regarding HashMap in Java, ask in the comment tab.<\/span><\/p>\n<p><strong>See also &#8211;\u00a0<\/strong><\/p>\n<p><strong>J<\/strong><strong>ava Quiz<a href=\"https:\/\/data-flair.training\/blogs\/java-quiz\/\"> Part 1<\/a> &amp; <a href=\"https:\/\/data-flair.training\/blogs\/java-online-quiz\/\">Part 2<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/docs.oracle.com\/\">For reference<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, in this Java HashMap tutorial, we are going to learn about the HashMap in Java. First, we will start with the meaning of Java HashMap. Moreover, we will learn about constructors and methods&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":21599,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[2939,4293,5374,5377,7525,7526,7527,7528,7529,7530,8691,9468],"class_list":["post-21534","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-constructors-of-hashmap-in-java","tag-example-of-java-hashmap","tag-hashmap-implementation-in-java","tag-hashtable-java","tag-java-hashmap-constructors","tag-java-hashmap-definition","tag-java-hashmap-example","tag-java-hashmap-methods","tag-java-hashmap-performance","tag-java-hashmap-tutorial","tag-methods-of-hashmap-in-java","tag-performance-of-hashmap"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java HashMap | Constructors &amp; Methods of HashMap in Java - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn what is Hashmap in Java with examples, its Constructors, internal structures and methods of Hashmap in java\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/java-hashmap\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java HashMap | Constructors &amp; Methods of HashMap in Java - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn what is Hashmap in Java with examples, its Constructors, internal structures and methods of Hashmap in java\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/java-hashmap\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-17T04:00:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-22T12:06:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java HashMap | Constructors &amp; Methods of HashMap in Java - DataFlair","description":"Learn what is Hashmap in Java with examples, its Constructors, internal structures and methods of Hashmap in java","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:\/\/data-flair.training\/blogs\/java-hashmap\/","og_locale":"en_US","og_type":"article","og_title":"Java HashMap | Constructors &amp; Methods of HashMap in Java - DataFlair","og_description":"Learn what is Hashmap in Java with examples, its Constructors, internal structures and methods of Hashmap in java","og_url":"https:\/\/data-flair.training\/blogs\/java-hashmap\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-07-17T04:00:56+00:00","article_modified_time":"2026-05-22T12:06:50+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Java HashMap | Constructors &amp; Methods of HashMap in Java","datePublished":"2018-07-17T04:00:56+00:00","dateModified":"2026-05-22T12:06:50+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/"},"wordCount":1635,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01.jpg","keywords":["Constructors of Hashmap in Java","example of java hashmap","hashmap implementation in Java","hashtable Java","Java HashMap Constructors","Java Hashmap definition","Java HashMap Example","Java hashmap Methods","Java HashMap Performance","Java HashMap tutorial","Methods of HashMap in Java","Performance of HashMap"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/java-hashmap\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/","url":"https:\/\/data-flair.training\/blogs\/java-hashmap\/","name":"Java HashMap | Constructors &amp; Methods of HashMap in Java - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01.jpg","datePublished":"2018-07-17T04:00:56+00:00","dateModified":"2026-05-22T12:06:50+00:00","description":"Learn what is Hashmap in Java with examples, its Constructors, internal structures and methods of Hashmap in java","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/java-hashmap\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Java-HashMap-01.jpg","width":1200,"height":628,"caption":"Java HashMap | Constructors &amp; Methods of HashMap in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/java-hashmap\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Java Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/java\/"},{"@type":"ListItem","position":3,"name":"Java HashMap | Constructors &amp; Methods of HashMap in Java"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/21534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=21534"}],"version-history":[{"count":11,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/21534\/revisions"}],"predecessor-version":[{"id":148419,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/21534\/revisions\/148419"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/21599"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=21534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=21534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=21534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}