Java set (list, set, map) features, setmap
There are a lot of classes related to the set. Generally, they only use common methods for addition, deletion, modification, and query, and their method names are basically the same, so they never know when to use the set,
Today, I am free to sort out materials from the Internet to facilitate future memories.
1. List: sequential linear storage, which can store repeated objects
Thread security method: List list = Collections. synchronizedList (new synchronized List (...));
Slow list: two-way linked list to store index data with slow insertion speed and low thread security (better than security performance)
ArrayList: array-based storage of data index data fast insertion of Data slow thread is not safe
Vector: array-based data index data fast insertion data slow thread safety
Stack: inherits from the Vector to implement a post-import, first-out Stack.
2. Set: No sequence, no repeated Elements
HashSet: A Set designed for quick search. The object stored in the HashSet must define hashCode ().
TreeSet: The Set that stores the order. The bottom layer is the tree structure. It can be used to extract ordered sequences from the Set.
LinkedHashSet: query speed with a HashSet, and internal use of the linked list to maintain the order of elements (insert order ). When you use the iterator to traverse the Set, the result is displayed in the order of element insertion.
3. Map: The key must be unique.
Synchronization Method: Map m = Collections. synchronizedMap (new TreeMap (...));
Hashtable: Allows thread security for null keys based on Hash
HashMap: hash-based implementation that allows empty keys to be null threads is not safe (basically consistent with Hashtable)
TreeMap: The implementation based on the data structure of the red/black tree does not allow insecure threads with null keys
WeakHashMap: improved HashMap, which implements "weak reference" for the key. If a key is no longer referenced by external entities, it can be recycled by GC.
HashSet and HashMap should be used in addition to TreeSet and TreeMap for sorting, because they are more efficient.
Iv. SparseArray <E>: stores data in a binary method (a collection class of Android)
In android, we recommend that you use SparseArray <E> instead of HashMap <Integer, E>.
The use of SparseArray is basically the same as the List, in some do not explain in detail, you can see the http://blog.csdn.net/xyz_fly/article/details/793194