Common collection classes Collections

ArrayList:
Implements List interface, List interface inherits Collections interface
1. Based on array implementation (Object array), it has the characteristics of array: fast query and modification, slow insertion and deletion;
2. Initial capacity is 10;
3. It is better to have initial capacity when using, Otherwise, an empty array will be created. When an element is added for the first time, an array with a capacity of 10 will be created again;
4. Delete and insert operations: all elements after a specific element will be moved and the array will be copied (repeat each time). Generate an array, copy the element array to the new array),
each time an element is inserted or added, it will check whether the array capacity is sufficient, otherwise it will be expanded, and each expansion will increase the length of the original array by half, so it is relatively slow ;
5. Modify and query, locate specific elements according to the subscript index, do not involve moving elements and copying arrays, so the operation is fast;
6. All methods are asynchronous, so they are not thread-safe;
7. Implement RandomAccess interface , which can be accessed randomly and quickly by subscript index;
8. The collable interface is implemented, and elements can be cloned into a new Arraylist;

 

LinkedList:
Implement List interface, List interface inherits Collections interface
1. Based on doubly linked list implementation. Each node contains three elements (pre-node reference, current node value, post-node reference);
2. No need to specify capacity;
3. Add and insert are mainly realized by linklast and linkbefore methods, and deletion is realized by unlink method, two operations Both operate on the specified element and adjacent elements, which is relatively fast;
4. Both query and modification operations need to call the node (int index) method to traverse the linked list to locate elements, so it is slow;
5. All methods are asynchronous, so non-synchronized Thread safety;
6. Implements the collable interface, which can clone elements into a new LinkedList;

 

Vector:
Implements the List interface, and the List interface inherits the Collections interface
1. The method is synchronized, so it is thread-safe;
2. The default capacity is twice the original, and the value of each expansion can also be defined;
3. The default initial capacity is 10;
4. Based on Object array implementation, similar to arraylist, so query and modification are fast, deletion and addition are slow;
5. RandomAccess interface is implemented, which can be accessed randomly and quickly through subscript index;
6. Collable interface is implemented, which can clone elements into a new vector middle;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324382371&siteId=291194637