Features of the Java collection (list, set, map)

Source: Internet
Author: User

Collection related classes have a large heap, generally only use the usual methods and additions and deletions, and it's their method name is basically the same, so always do not know when to use what set,

Today, while you are free to organize information from the Internet to facilitate future memories.

A, List:, sequentially stored in a linear manner, can hold duplicate objects

Thread-Safe methods: List List = Collections.synchronizedlist (new LinkedList (...));

LinkedList: Two-way linked list for storing index data slow insertion several faster threads are unsafe (better than security)

ArrayList: Array way to store data index data fast insert data slow thread insecure

Vector: Array way to store data index data fast insert data slow thread safety

Stack: Inherits from Vector, implements a last-in-first-out stack

Second, Set: no order, no duplicate elements

HashSet: Set for quick find design. The object that is deposited into the hashset must define HASHCODE ().

TreeSet: The set of the save order, the underlying tree structure. Use it to extract ordered sequences from the set.

Linkedhashset: has hashset query speed, and internally uses the chain list to maintain the order of elements (the Order of insertions). The result is displayed in the order in which the elements are inserted when iterating through the set using Iterators.

Third, Map: The key must be unique

Synchronization method: Map m = collections.synchronizedmap (new TreeMap (...));

Hashtable: Hash List-based implementation allows NULL key null-value thread safety

HASHMAP: Hash List-based implementation allows NULL-key null-value thread insecure (basically consistent with Hashtable)

TREEMAP: implementation based on red and black tree data structure does not allow null key NULL thread unsafe

Weakhashmap: Improved HashMap, which implements a "weak reference" to key, which can be recycled by GC if a key is no longer referenced externally.

Use Hashset,hashmap in addition to treeset,treemap when sorting is required, because they are more efficient.

Iv. Sparsearray<e>: Two-point method for storing data (a collection class for Android)

The Android system suggests we use sparsearray<e> instead of Hashmap<integer, e>

Sparsearray the use of basic and list, in some not detailed explanation, we can see http://blog.csdn.net/xyz_fly/article/details/793194

Features of the Java collection (list, set, map)

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.