Articles

Difference Hashmap vs Hashtable in java

Difference Hashmap vs Hashtable in java


In this java interview questions, we will learn about:

  •  hashmap vs hashtable in java

Hashmap vs Hashtable in java

Difference between HashMap and HashTable is highlighted below based on the following parameters:
 
Synchronized Nature
HashMap is not synchronized in nature.
HashTable is synchronized in nature.
 
Traversal
HashMap can be traversed by using an iterator.
HashTable can be traversed by using an iterator or enumerator.
 
Null value/key
HashMap allows only one null key and any number of null values.
HashTable doesn't allow key or value to be null.
 
fail-fast nature of iterator or enumerator
Iterator in HashMap is fail-fast.
Enumerator in HashTable is not fail-fast.
 
Performance
HashMap is faster in terms of performance.
HashTable is slower in comparision to HashMap in terms of performance.
 
Reason: Since HashTable is synchronized in nature so it doesn't allow multi-threading operation on a particular resource at a time thus turning out to be slower than HashMap which is non-synchronized by nature.
 

Java Interview Questions

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Sonu Pandit
I am editor in chief at tutorialsinhand.com responsible for managing, reviewing and sending articles/contents for final approval to get published. Connect with me@https://www.linkedin.com/in/sonu-pandit-a77b471ab/. Join write4us program & share your skill
Page Views :    Published Date : Dec 21,2020  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!