The similarities and differences between Java Foundation---HashMap and Hashtable

Source: Internet
Author: User

1: Even a map interface is implemented, the underlying data structure is the same, both are transient decorated entry array, transient modified variables will not be serialized is not persisted, the process of serialization will not include this variable, The lifetime of this variable is simply not persisted to the memory disk during the user's call. This facilitates the preservation of some sensitive information

2:hashmap is insecure, cannot be synchronized, does not support multithreading concurrency, Hashtable is secure, has a synchronous lock, but is inefficient.

3:hashmap inherited from Abstractmap, Hashtable inherited from dictionary.

4:hashmap allows NULL to exist, indicating that the value of key does not exist or is null. And Hashtable cannot have null

The hash of the 5:hashtable is the hash of the object directly, and the HashMap to recalculate the hash value, thus more hashing, which helps to reduce the conflict. Increase efficiency

6:hashtable can use Itertor to implement traversal, HashMap can also use this, but in the early version Hashtable can also use enumeration to traverse

7:hashtable the size of the default initialization array is 11, you can specify the initialization size of the array, the rules for expansion are old*2+1,

HashMap The default array size is 16, the length remains a multiple of 2, and the size of the minimum 2 that is greater than initcaptiy is selected for expansion

82 supports FF failure mechanism

The similarities and differences between Java Foundation---HashMap and Hashtable

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.