What are the differences between a HashMap and a Hashtable in Java?
Which is more efficient for non-threaded applications?
What are the differences between a HashMap and a Hashtable in Java?
Which is more efficient for non-threaded applications?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Uday DodiyaPosted Sep 21, 2022, 9:41 AM
Hi Jaya,
There are several differences between HashMap and Hashtable in Java:
Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.
Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
One of HashMap's subclasses is LinkedHashMap, so if you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.
Since synchronization is not an issue for you, I'd recommend HashMap. If synchronization becomes an issue, you may also look at ConcurrentHashMap
Dhanush KPosted Oct 21, 2024, 12:29 PM
Hashtableis synchronized. If a thread-safe implementation is not needed, it is recommended to useHashMapin place ofHashtable. If a thread-safe highly-concurrent implementation is desired, then it is recommended to useConcurrentHashMapin place ofHashtable.Amit KumarPosted Sep 21, 2022, 10:37 AM
Hi ,
Differences are.
For more detail
https://www.geeksforgeeks.org/differences-between-hashmap-and-hashtable-in-java/#:~:text=Hashmap%20vs%20Hashtable&text=It%20is%20thread%2Dsafe%20and,thread%20synchronization%20is%20not%20needed.