PS: This blog mainly refers to the underlying source code of jdk, rather than writing code by yourself.
What is the difference between ArrayList, struct list, and Vector?
① The underlying layer of ArrayList is actually implemented using arrays (and the Object type of the array)
② If JDK 6 is used, Array is used. the copyOf () method is used to generate a new array. If jdk5 is used, the System is used. arraycopy () method (when the added data volume exceeds the length of the array)
③ When List list = newArrayList (), an array with a length of 10 is generated at the underlying layer to store objects.
④ The underlying layers of ArrayList and Vector are implemented using arrays.
⑤ For ArrayList, the methods are not synchronized. For Vector, most public methods are synchronized.
⑥ Using a two-way circular linked list
7. For ArrayList, the query speed is very fast, and the addition and deletion (not the last node) operations are very slow (essentially determined by the features of the array)
The slow query speed is very slow for the slow list, and the addition and deletion operations are very fast (essentially determined by the two-way cyclic linked list)
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KMaGiQXJyYXlMaXN0tcTErMjPubnU7Le9t6i0 + sLro6iw/MCoz + rotate "brush: java;"> private transient Object elementData []; public ArrayList (int I) {if (I <0) {throw new IllegalArgumentException (new StringBuilder ()). append ("Illegal Capacity :"). append (I ). toString ();} else {elementData = new Object [I]; return ;}} public ArrayList () {this (10 );}
2. Default LinkList Constructor (including related code)
public LinkedList() {header = new Entry(null, null, null);size = 0;header.next = header.previous = header;}private static class Entry {Object element;Entry next;Entry previous;Entry(Object obj, Entry entry1, Entry entry2) {element = obj;next = entry1;previous = entry2;}}private transient Entry header;private transient int size;3. Default Vector Constructor (including related code)
public Vector(int i, int j) {if (i < 0) {throw new IllegalArgumentException((new StringBuilder()).append("Illegal Capacity: ").append(i).toString());} else {elementData = new Object[i];capacityIncrement = j;return;}}public Vector(int i) {this(i, 0);}public Vector() {this(10);}protected Object elementData[];protected int capacityIncrement;