Java collection class (two) commonly used implementation class of List collection

一.ArrayList

The underlying data structure of ArrayList is a dynamic array, which is fast in query and slow in addition and deletion . When the no-argument constructor is called to create an ArrayList object, the default size is 10 . When the array needs to be expanded later, a new array will be generated, the size of which is 1.5 times the size of the original array , and then the original array elements will be copied to the new array.
常用方法: Get(int index), set(int index, E e), add(E e), remove(E e), remove(int index), etc.

二.LinkedList

The underlying data structure is based on a doubly linked list, with fast additions and deletions, high efficiency of the sequential method, low efficiency of random access, and unsafe threads .
LinkList implements the List interface, and also inherits methods containing indexes such as get(int i). The LinkList itself is a linked list, so where does its index come from?
View the source code of the LinkList part as follows: (JDK13)
Insert picture description here
When we pass in an index value, the index value and the length of the current linked list will first be shifted one bit to the right and then compared. If the index is smaller, it will be traversed from beginning to end; Otherwise, it traverses from end to beginning until the target position. The purpose is to reduce the number of traversals.

Three.Vector

Vector is a thread-safe ArrayList , but its efficiency is reduced. Compared with ArrayList, the expansion mechanism of Vector is different. The size of the new array constructed by default each time is twice the original size.

Guess you like

Origin blog.csdn.net/m0_46550452/article/details/107249295