The Java list interface has 3 implementation classes, ArrayList, LinkedList, and vectors, which are used to store multiple elements, maintain the order of elements, and allow elements to be duplicated.
The differences between the 3 specific implementation classes are as follows:
1. ArrayList is the most commonly used list implementation class, implemented internally by an array, which allows for fast random access to elements. The disadvantage of an array is that there can be no interval between each element, and when the array size does not meet the need to increase storage capacity, the data that already has the array is copied into the new storage space. When inserting or deleting elements from the middle of a ArrayList, it is necessary to copy, move, and cost the array. Therefore, it is suitable for random lookups and traversal, not suitable for insertions and deletions, allowing empty elements
2. Vectors, like ArrayList, are also implemented by arrays, except that it supports thread synchronization, where only one thread can write vectors at a time, avoiding inconsistencies caused by simultaneous writing of multiple threads, but achieving synchronization requires a high cost, so Accessing it is slower than accessing ArrayList.
3. LinkedList is used to store data in a linked list structure, which is suitable for dynamic insertion and deletion of data, and is slow in random access and traversal. In addition, there is no method get,remove,insertlist defined in the interface, specifically for manipulating the header and footer elements, which can be used as stacks, queues, and bidirectional queues. LinkedList There is no synchronization method. If multiple threads access a list at the same time, you must implement access synchronization yourself. One workaround is to construct a synchronized list when the list is created:
List List = Collections.synchronizedlist (new LinkedList (...));
Look at the Java source code, and find that when the size of the array is not enough, you need to re-establish the array, and then copy the elements into the new array, the size of the ArrayList and vector extended array is different.
This is on the Internet. ArrayList detailed Description: http://zhangshixi.iteye.com/blog/674856
Java Collections: List Learning