What is the difference between Java vs. Hashtable, Hashmap, TreeMap? (Studying in progress)

Source: Internet
Author: User

Hashtable, Hashmap, and TreeMap are the most common map implementations, which are container types that store and manipulate data in the form of key-value pairs.

Hashtable is a hash implementation provided by the Java class Library that is inherently synchronous, does not support null keys and null values, and is rarely recommended because of the performance overhead associated with synchronization.

HashMap is the application of a more extensive hash table implementation, the behavior is roughly consistent with Hashtable, the main difference is that HashMap is not synchronous, support null keys and null values and so on. Typically, the HashMap performs a get and put operation to achieve constant time performance, so it is the most preferred choice for accessing the scene using key values.

TreeMap is based on a red-black tree to provide sequential access to the map, its get, put, remove and other operations are the time complexity of O (Logn), the specific order can be determined by the specified comparator, or according to the natural order of the keys to judge.

What is the difference between Java vs. Hashtable, Hashmap, TreeMap? (Studying in progress)

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.