What are the differences between a HashMap and a Hashtable in Java?

后端 未结 30 2381
青春惊慌失措
青春惊慌失措 2020-11-21 13:30

What are the differences between a HashMap and a Hashtable in Java?

Which is more efficient for non-threaded applications?

30条回答
  •  醉话见心
    2020-11-21 13:54

    HashMap and HashTable

    • Some important points about HashMap and HashTable. please read below details.

    1) Hashtable and Hashmap implement the java.util.Map interface 2) Both Hashmap and Hashtable is the hash based collection. and working on hashing. so these are similarity of HashMap and HashTable.

    • What is the difference between HashMap and HashTable?

    1) First difference is HashMap is not thread safe While HashTable is ThreadSafe
    2) HashMap is performance wise better because it is not thread safe. while Hashtable performance wise is not better because it is thread safe. so multiple thread can not access Hashtable at the same time.

提交回复
热议问题