Differences between hashmap and hashtable in Java learning)

Source: Internet
Author: User
Hashmap is Hashtable Lightweight implementation (non-thread-safe implementation), they have completed Map Interface, the main difference is that Hashmap Allow null ( Null ) Key value ( Key ) , Because of non-thread security, the efficiency may be higher Hashtable .
Hashmap
Allow Null As Entry Of Key Or Value , And Hashtable Not allowed.
Hashmap
Set Hashtable Of Contains The method is removed and changed Containsvalue And Containskey . Because Contains Methods are easy to misunderstand.
Hashtable
Inherited from Dictionary Class, while Hashmap Yes Java1.2 Imported Map Interface .
The biggest difference is that, Hashtable The method is Synchronize And Hashmap No, access in multiple threads Hashtable You do not need to implement synchronization for its own method. Hashmap You must provide external synchronization for it.
Hashtable
And Hashmap Used Hash/rehash Algorithm So the performance will not be significantly different.

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.