The difference between Hashtable and HashMap under the Java JDK

Source: Internet
Author: User

Time Angle: Hashtable * @since JDK1.0 ; HashMap * @since 1.2

base class and interface angle:

public class Hashtable<k,v>
Extends dictionary<k,v>
Implements Map<k,v>, Cloneable, java.io.Serializable

public class Hashmap<k,v>
Extends abstractmap<k,v>
Implements Map<k,v>, Cloneable, Serializable

Implements the same interface, inheriting from different base classes (dictionaries) dictionary<k,v> with (abstract mappings) abstractmap<k,v>.

Thread-Safe angle:

Hashmap.java:

* <p><strong>note that this implementation are not synchronized.</strong>
* If Multiple threads access a hash map concurrently, and at least one of
* The threads modifies the map structurally, it <i>must</i> be
* Synchronized externally. (A structural modification is any operation
* that adds or deletes one or more mappings; Merely changing the value
* Associated with a key, an instance already contains are not a
* Structural modification.) This was typically accomplished by
* Synchronizing on some object that naturally encapsulates the map.

Hashtable.java:

* Java collections Framework</a>. Unlike the new collection
* implementations, {@code Hashtable} is synchronized. If A
* Thread-safe implementation is not needed, it's recommended to use
* {@link HashMap} in place of {@code Hashtable}. If a Thread-safe
* Highly-concurrent implementation is desired and then it's recommended
* To use {@link Java.util.concurrent.ConcurrentHashMap}
* {@code Hashtable}.

The difference between Hashtable and HashMap under the Java JDK

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.