One.
All the dashed boxes are interfaces, we are actually using the sub-class in the interface,
The list interface, which has a bunch of subclasses, is a common container in our development. Arraylist,linklist,vecter these three are considered to be more commonly used in development.
(There are three common objects below the list)
The specific container must be clear about its characteristics, then you know when to use the container.
1. Vector
Containers can be distinguished because the internal data structure of the container is different, and now the vector is using an array. The array itself is a way of storing data, which is itself a structure. This structure is characterized by the fact that each element is numbered and stored continuously. A space to open up, a lot of small lattice will come out.
Vetor from the 1.0 version, this interface 1.2 only come out (Vetor is long ago, but the sub-class interface called the list interface is starting from 1.2),
In 1.0, the set of the use of a vetor, to 1.2 has a set of framework, only add a variety of data structure came in, produced a system. When I was 1.2, Vetor was included, Vetor was the elder, and it was 1.2 to implement the list, to have the list function, and to be a member of the Java Collection framework. The vetor is synchronous, which means the thread is secure.
2. ArrayList
The interior is also an array structure, and is mutable, and is out of sync. Why there is ArrayList, because the Vetor synchronization efficiency is low. Structure is the same, why should there be two, because the substitution of vetor. What if it's multithreaded? Using Vetor? (no), we either lock the ArrayList or use other methods. Vetor almost no more. How do you lock it? Put the methods that add and delete into the same lock.
A variable size array has been raised in ArrayList, and an array of objects that can be grown is also mentioned in Vetor. What is a variable-length array? When we were studying, the array was fixed length, how does the collection implement constantly adding elements to it? Variable-length array principle, create a new array, copy the contents of the original array into the new array.
Vetor is certain to lengthen, ArrayList is half the chance of lengthening. Vetor is a waste of space, but also waste efficiency, ArrayList will be stronger than Vetor.
3. LinkedList
Link list for short link lists.
The set, as long as it is not vetor, is unsynchronized because of its high efficiency.
What are the characteristics of a linked list? How do arrays store elements? Cut the space into smaller squares and store the elements in. How to store it in? An array opens up a space, with a corner mark that stores elements according to the angle label.
The list is like this: the lattice of the previous element, remembering the value of the next element's corner mark.
List structure If you delete an element, you just need to remember the next element's corner mark value.
Why do you want data structure, is not the same operation, the operation characteristics are different. Linked lists This structure removes elements at a rapid rate.
Java-preliminary Understanding-Common Object API (collection framework-list common subclass features)