{"id":1891,"date":"2023-09-13T05:38:38","date_gmt":"2023-09-13T05:38:38","guid":{"rendered":"https:\/\/datmt.com\/?p=1891"},"modified":"2023-09-17T17:16:00","modified_gmt":"2023-09-17T17:16:00","slug":"4-key-differences-between-a-hashmap-and-a-hashtable-in-java","status":"publish","type":"post","link":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/","title":{"rendered":"4 Key differences between a HashMap and a Hashtable in Java"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>Hashtable and HashMap are common data structures to store key-value data in your Java application. While having similarities, there are some crucial differences you need to know as a Java developer. Let&#8217;s discuss the differences between these two data structures in this post.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hashtable is thread-safe, HashMap is not<\/h2>\n\n\n\n<p>Consider the following code using HashMap:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">    public static void main(String[] args) {\n        \/\/demonstrate the differences between HashMap and HashTable regarding synchronization\n        var myMap = new HashMap&lt;String, Integer&gt;();\n        myMap.put(&quot;key1&quot;, 1);\n\n        \/\/spawn 10 threads to modify the value of &quot;key1&quot;\n        for (int i = 0; i &lt; 10; i++) {\n            new Thread(() -&gt; {\n                myMap.put(&quot;key1&quot;, myMap.get(&quot;key1&quot;) + 1);\n            }).start();\n        }\n\n        \/\/wait for all threads to finish\n        try {\n            Thread.sleep(1000);\n        } catch (InterruptedException e) {\n            e.printStackTrace();\n        }\n\n        System.out.println(myMap.get(&quot;key1&quot;));\n\n    }<\/pre><\/div>\n\n\n\n<p>What would this code print? The answer is no one knows for sure. Since HashMap is not thread-safe, some updates could be lost in the code above.<\/p>\n\n\n\n<p>In fact, running the code multiple times would produce different result. This is one example:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"522\" height=\"152\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" src=\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/image-1.png\" alt=\"HashMap is not thread-safe\" class=\"wp-image-1892\" srcset=\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/image-1.png 522w, https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/image-1-300x87.png 300w\" \/><figcaption class=\"wp-element-caption\">HashMap is not thread-safe<\/figcaption><\/figure>\n\n\n\n<p>On the other hand, using HashTable would solve the issue:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">\t\tvar myTable = new Hashtable&lt;String, Integer&gt;();\n        myTable.put(&quot;key1&quot;, 1);\n\n        \/\/spawn 100 threads to modify the value of &quot;key1&quot;\n        for (int i = 0; i &lt; 100; i++) {\n            new Thread(() -&gt; {\n                myTable.put(&quot;key1&quot;, myTable.get(&quot;key1&quot;) + 1);\n            }).start();\n        }\n\n        \/\/wait for all threads to finish\n        try {\n            Thread.sleep(1000);\n        } catch (InterruptedException e) {\n            e.printStackTrace();\n        }\n\n        System.out.println(&quot;Result using HashTable: &quot; + myTable.get(&quot;key1&quot;));<\/pre><\/div>\n\n\n\n<p>The result is consistent, for the above code, I always get 101 returned. <\/p>\n\n\n\n<p>But why HashTable is thread-safe and HashMap is not? It&#8217;s because if you look into the implementation of HashTable, all methods are synchronized while that&#8217;s not the case with HashMap.<\/p>\n\n\n\n<p>For example, this is the method put of HashTable:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">public synchronized V put(K key, V value) {\n\/\/...\n}<\/pre><\/div>\n\n\n\n<p>And this is the put method of HashMap<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">public V put(K key, V value) {\n        \/\/...\n}\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">HashMap allows null key &amp; value, HashTable doesn&#8217;t<\/h2>\n\n\n\n<p>The following code would throw NullPointerException (on line 2, if you comment line 2, the exception is still thrown by line 3)<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">var myTable = new Hashtable&lt;String, Integer&gt;();\nmyTable.put(null, 100);\nmytable.put(&quot;Key2&quot;, null);\n\n<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"490\" height=\"150\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" src=\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/image-2.png\" alt=\"You cannot use null as key or value with HashTable\" class=\"wp-image-1893\" srcset=\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/image-2.png 490w, https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/image-2-300x92.png 300w\" \/><figcaption class=\"wp-element-caption\">You cannot use null as a key or value with HashTable<\/figcaption><\/figure>\n\n\n\n<p>However, if I use HashMap, there is not exception thrown at run time:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">var myMap= new HashMap&lt;String, Integer&gt;();\nmyMap.put(&quot;key1&quot;, null);\nmyMap.put(null, 100);\n\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Performance<\/h2>\n\n\n\n<p>In single-thread applications, HashMap tends to perform better due to the lack of synchronization. However, in multiple thread applications, you need to use synchronization on operations involving HashMap to maintain data integrity, which would put a cost on performance too. <\/p>\n\n\n\n<p>Let&#8217;s consider the operation of creating a HashTable and a HashMap with 1_000_000 entries<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">    public static void main(String[] args) {\n        var myMap= new HashMap&lt;String, Integer&gt;();\n        var myTable = new Hashtable&lt;String, Integer&gt;();\n\n        var beforeAddingToHashTable = System.currentTimeMillis();\n        \/\/add 1000000 entries to HashTable\n        for (int i = 0; i &lt; 1_000_000; i++) {\n            myTable.put(&quot;key&quot; + i, i);\n        }\n        var afterAddingToHashTable = System.currentTimeMillis();\n\n        var beforeAddingToHashMap = System.currentTimeMillis();\n\n        \/\/add 1000000 entries to HashMap\n        for (int i = 0; i &lt; 1_000_000; i++) {\n            myMap.put(&quot;key&quot; + i, i);\n        }\n\n        var afterAddingToHashMap = System.currentTimeMillis();\n\n        \/\/compare the result\n        System.out.println(&quot;Time to add 1000000 entries to HashTable: &quot; + (afterAddingToHashTable - beforeAddingToHashTable));\n        System.out.println(&quot;Time to add 1000000 entries to HashMap: &quot; + (afterAddingToHashMap - beforeAddingToHashMap));\n    }\n<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"513\" height=\"169\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" src=\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/image-3.png\" alt=\"\" class=\"wp-image-1894\" srcset=\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/image-3.png 513w, https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/image-3-300x99.png 300w\" \/><\/figure>\n\n\n\n<p>Generally, the time taken to complete the operations on a HashMap is less than that of a HashTable. However, it depends on the condition of your machine and how large is the set.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Iterating over Entries<\/h2>\n\n\n\n<p>HashMap: HashMap allows you to iterate over its entries using an enhanced for loop or iterators. It provides methods like keySet(), values(), and entrySet() for this purpose.<\/p>\n\n\n\n<p>Hashtable: Hashtable also offers methods for iteration, similar to HashMap. You can use keys(), values(), and entrySet().<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">        var myMap= new HashMap&lt;String, Integer&gt;();\n        var myTable = new Hashtable&lt;String, Integer&gt;();\n\n        myMap.put(&quot;Key1&quot;, 100);\n        myMap.put(&quot;Key2&quot;, 200);\n\n        myTable.put(&quot;Key1&quot;, 100);\n        myTable.put(&quot;Key2&quot;, 200);\n\n        \/\/Iterate over the map\n        for (var entry : myMap.entrySet()) {\n            System.out.println(entry.getKey() + &quot; &quot; + entry.getValue());\n        }\n\n        myMap.values();\n        \/\/myMap.keys(); \/\/this will not compile\n\n        \/\/Iterate over the table\n        for (var entry : myTable.entrySet()) {\n            System.out.println(entry.getKey() + &quot; &quot; + entry.getValue());\n        }\n\n        myTable.keys();\n        myTable.values();\n\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>There you have it, the core differences between HashTable and HashMap in Java:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>HashTable is thread-safe (by marking methods with synchronized) while HashMap is not<\/li>\n\n\n\n<li>HashMap is generally faster on single-threaded applications due to the lack of synchronization<\/li>\n\n\n\n<li>HashTable offers keys() to iterate over keys<\/li>\n\n\n\n<li>HashMap allows null key and value while HashTable doesn&#8217;t<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Overview Hashtable and HashMap are common data structures to store key-value data in your Java application. While having similarities, there are some crucial differences you need to know as a Java developer. Let&#8217;s discuss the differences between these two data structures in this post. Hashtable is thread-safe, HashMap is not Consider the following code using &#8230; <a title=\"4 Key differences between a HashMap and a Hashtable in Java\" class=\"read-more\" href=\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/\" aria-label=\"Read more about 4 Key differences between a HashMap and a Hashtable in Java\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":1897,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[4],"tags":[101,73],"class_list":["post-1891","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java","tag-java-core"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>4 Key differences between a HashMap and a Hashtable in Java - datmt<\/title>\n<meta name=\"description\" content=\"Learn the most important differences between a HashMap and a Hashtable 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:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"4 Key differences between a HashMap and a Hashtable in Java - datmt\" \/>\n<meta property=\"og:description\" content=\"Learn the most important differences between a HashMap and a Hashtable in Java\" \/>\n<meta property=\"og:url\" content=\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"datmt\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-13T05:38:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-17T17:16:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"\u0110\u1ea1t Tr\u1ea7n\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u0110\u1ea1t Tr\u1ea7n\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/\"},\"author\":{\"name\":\"\u0110\u1ea1t Tr\u1ea7n\",\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\"},\"headline\":\"4 Key differences between a HashMap and a Hashtable in Java\",\"datePublished\":\"2023-09-13T05:38:38+00:00\",\"dateModified\":\"2023-09-17T17:16:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/\"},\"wordCount\":427,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\"},\"image\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png\",\"keywords\":[\"java\",\"java core\"],\"articleSection\":[\"java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/\",\"url\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/\",\"name\":\"4 Key differences between a HashMap and a Hashtable in Java - datmt\",\"isPartOf\":{\"@id\":\"https:\/\/datmt.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png\",\"datePublished\":\"2023-09-13T05:38:38+00:00\",\"dateModified\":\"2023-09-17T17:16:00+00:00\",\"description\":\"Learn the most important differences between a HashMap and a Hashtable in Java\",\"breadcrumb\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#primaryimage\",\"url\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png\",\"contentUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png\",\"width\":1280,\"height\":720,\"caption\":\"4 Key differences between a HashMap and a Hashtable in Java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/datmt.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"4 Key differences between a HashMap and a Hashtable in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/datmt.com\/#website\",\"url\":\"https:\/\/datmt.com\/\",\"name\":\"datmt\",\"description\":\"Hands on projects\",\"publisher\":{\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/datmt.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\",\"name\":\"\u0110\u1ea1t Tr\u1ea7n\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg\",\"contentUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg\",\"width\":512,\"height\":512,\"caption\":\"\u0110\u1ea1t Tr\u1ea7n\"},\"logo\":{\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/image\/\"},\"description\":\"I build softwares that solve problems. I also love writing\/documenting things I learn\/want to learn.\",\"sameAs\":[\"https:\/\/datmt.com\"],\"url\":\"https:\/\/datmt.com\/author\/mtdat171_c\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"4 Key differences between a HashMap and a Hashtable in Java - datmt","description":"Learn the most important differences between a HashMap and a Hashtable 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:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/","og_locale":"en_US","og_type":"article","og_title":"4 Key differences between a HashMap and a Hashtable in Java - datmt","og_description":"Learn the most important differences between a HashMap and a Hashtable in Java","og_url":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/","og_site_name":"datmt","article_published_time":"2023-09-13T05:38:38+00:00","article_modified_time":"2023-09-17T17:16:00+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png","type":"image\/png"}],"author":"\u0110\u1ea1t Tr\u1ea7n","twitter_card":"summary_large_image","twitter_misc":{"Written by":"\u0110\u1ea1t Tr\u1ea7n","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#article","isPartOf":{"@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/"},"author":{"name":"\u0110\u1ea1t Tr\u1ea7n","@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e"},"headline":"4 Key differences between a HashMap and a Hashtable in Java","datePublished":"2023-09-13T05:38:38+00:00","dateModified":"2023-09-17T17:16:00+00:00","mainEntityOfPage":{"@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/"},"wordCount":427,"commentCount":0,"publisher":{"@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e"},"image":{"@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png","keywords":["java","java core"],"articleSection":["java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/","url":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/","name":"4 Key differences between a HashMap and a Hashtable in Java - datmt","isPartOf":{"@id":"https:\/\/datmt.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#primaryimage"},"image":{"@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png","datePublished":"2023-09-13T05:38:38+00:00","dateModified":"2023-09-17T17:16:00+00:00","description":"Learn the most important differences between a HashMap and a Hashtable in Java","breadcrumb":{"@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#primaryimage","url":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png","contentUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/09\/4-Key-differences-between-a-HashMap-and-a-Hashtable-in-Java.png","width":1280,"height":720,"caption":"4 Key differences between a HashMap and a Hashtable in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/datmt.com\/backend\/java\/4-key-differences-between-a-hashmap-and-a-hashtable-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/datmt.com\/"},{"@type":"ListItem","position":2,"name":"4 Key differences between a HashMap and a Hashtable in Java"}]},{"@type":"WebSite","@id":"https:\/\/datmt.com\/#website","url":"https:\/\/datmt.com\/","name":"datmt","description":"Hands on projects","publisher":{"@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/datmt.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e","name":"\u0110\u1ea1t Tr\u1ea7n","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/datmt.com\/#\/schema\/person\/image\/","url":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg","contentUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg","width":512,"height":512,"caption":"\u0110\u1ea1t Tr\u1ea7n"},"logo":{"@id":"https:\/\/datmt.com\/#\/schema\/person\/image\/"},"description":"I build softwares that solve problems. I also love writing\/documenting things I learn\/want to learn.","sameAs":["https:\/\/datmt.com"],"url":"https:\/\/datmt.com\/author\/mtdat171_c\/"}]}},"_links":{"self":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts\/1891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/comments?post=1891"}],"version-history":[{"count":3,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts\/1891\/revisions"}],"predecessor-version":[{"id":1899,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts\/1891\/revisions\/1899"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/media\/1897"}],"wp:attachment":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/media?parent=1891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/categories?post=1891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/tags?post=1891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}