HashTable HashMap TreeMap Linkedhashmap Difference

Source: Internet
Author: User

Reference: http://blog.csdn.net/xiaodifa995455120/article/details/7277441

http://www.apkbus.com/forum.php?mod=viewthread&tid=52426

Hashmap is the most commonly used map, which stores data according to the hashcode value of the key, which can be obtained directly from the key, with fast access speed.
HashMap allows a maximum of one record's key to be null, allowing multiple records to have a value of NULL; HashMap does not support thread synchronization, where multiple threads can write HashMap at any one time, and may result in inconsistent data. If synchronization is required, you can use the collections Synchronizedmap method to make the HashMap capable of synchronizing. Statement block or method HashMap with synchronized adornment operation

Such as:

Map systemusers = Collections.synchronizedmap (New HashMap ());

HashTable It does not allow a record key or value to be null; it supports thread synchronization and is slow.

TreeMap is able to sort its saved records by key, by default in ascending order, or by specifying a sort comparer, when traversing treemap with iterator, the resulting record is unordered, and it does not allow the record key or value to be empty. Use: http://my.oschina.net/liyuanjinglyj/blog/126539 key value to implement comparable after the addition of automatic sorting, iterater read in order.

Linkedhashmap Linkedhashmap, the key and the value can be null, you can make the order of insertions, in the iterator traversal Linkedhashmap, the first obtained records must be inserted first. It is slower than hashmap when traversing.

HashTable HashMap TreeMap Linkedhashmap Difference

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.