Tag: Initialize the specified location Tor exce BSP thread-safe access pointer mechanism
1, Vector, ArrayList, LinkedList
Vectors and ArrayList are very similar in use, and can be used to represent a set of variable sets of object applications and to randomly access the elements within them.
Vector methods are synchronous (Synchronized), Thread-safe (Thread-safe), and ArrayList method is not, because thread synchronization must
To affect performance, ArrayList's performance is better than that of a vector.
ArrayList and LinkedList differences: For processing a list of data items, Java provides two classes of ArrayList and LinkedList. The internal implementation of the ArrayList is the base
In the internal array object[], so conceptually, it is more like an array, but the internal implementation of LinkedList is based on a set of connected records, so it is more like a linked table knot
So that they differ greatly in performance.
From the above analysis, we know that when inserting data in front or in the middle of a ArrayList, you must move all subsequent data accordingly, which will inevitably take a long time
, so when your action is to add data after a column of data instead of in front or in the middle, and you need to randomly access the elements in it, use Arraylis
T will provide better performance. When you access an element in a linked list, you must start at one end of the list and follow the direction of the connection in an element to find
To the desired element, so when your action is to add or delete data in front of or in the middle of a column of data, and to access the elements in order, you should
Use the LinkedList.
(Vector: Thread safety, ArrayList: unsafe, LinkedList: unsafe)
2, HashTable, HashMap, HashSet
Hashtable and HashMap adopt the same storage mechanism, the implementation of which is basically consistent.
The difference is:
1), HashMap is non-thread-safe, Hashtable is thread-safe, the internal method is basically synchronized.
2), Hashtable does not allow the existence of a null value. When the put method is called in Hashtable, if key is null, the NullPointerException is thrown directly.
Other subtle differences, such as initializing the size of the entry array, and so on, but the basic idea is the same as HashMap.
HashSet:
1, HashSet based on HASHMAP implementation, no capacity limit.
2, HashSet is non-thread-safe.
3, HashSet not guarantee orderly.
HASHMAP:
1, HashMap uses the array method to store the entry object composed of Key,value, no capacity limit.
2, HashMap based on the key hash to find entry objects stored in the location of the array, the hash conflict with a list of ways to solve.
3. HashMap may enlarge the capacity of the array when inserting the element, it is necessary to recalculate the hash when enlarging the capacity, and copy the object into the new array.
4, HashMap is non-thread-safe.
5, HashMap traversal is using the iterator
HashTable
1, Hashtable is thread-safe.
2. Neither key nor value in Hashtable is allowed to be null.
3, the Hashtable traversal uses is the enumeration.
3, TreeSet, TreeMap
TreeSet:
1, TreeSet based on TREEMAP implementation, support sorting.
2, TreeSet is non-thread-safe.
From the descriptions of HashSet and TreeSet, TreeSet and HashSet are completely map-based and do not support get (int) to
Gets the element at the specified position (traversal fetch is required), and TreeSet provides some sort support. For example, an incoming comparator implementation, Descendingset
and Descendingiterator and so on.
TREEMAP:
1, TreeMap is a typical red-black tree based map implementation, it is required to have a key comparison method, either passed into the comparator implementation, or key
The comparable object implements the interface.
2, TreeMap is non-thread-safe.
Thread Safety for Java collections