The differences between Java collections HashMap and Hashtable

Source: Internet
Author: User

HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), they all complete the map interface, mainly different from the hashmap allow null (NULL) key value (key), because of thread safety, more efficient than Hashtable.

HashMap allows NULL to be used as a entry key or value, and Hashtable is not allowed. HashMap Hashtable's contains (including) method was removed, changed to Containsvalue and ContainsKey. Because the contains method is easy to cause misunderstanding.

Hashtable inherits the Dictionary class, and HashMap is an implementation of the map interface introduced by Java1.2.

The biggest difference is that the Hashtable method is Synchroniz (synchronous), and HashMap is not, when multiple threads access Hashtable, they do not need to synchronize their methods, and HashMap must provide it with external synchronization.

The Hash/rehash algorithms used by Hashtable and HashMap are probably the same, so there's no big difference in performance.

The differences between Java collections HashMap and Hashtable

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.