ArrayList Use default parameterless constructor , Bottom Object The array length defaults to 10, When the length is not enough, use automatic growth 0.5 times

source code :

Default length 10

/** * Default initial capacity. */ private static final int DEFAULT_CAPACITY
= 10;

If the array length is not enough to grow 0.5 times grow method

int newCapacity = oldCapacity + (oldCapacity >> 1);

ArrayList Why is the query fast , Slow addition and deletion ?

Quick inquiry :

Because the array memory address arrangement is continuous , You can find it quickly, for example list.get(100); The first element memory address is 0x98, Then the memory address plus 100 I found it .

Slow addition and deletion :

increase :

Let's assume that the length of the array is 7, Now to add another element, what does it do ?

When adding elements , Check whether the array length is enough , If the bottom layer Object The array is not long enough , increase 0.5 Times the length , Form a new Object array , And set the previous array elements copy Into the new array

Delete :


Delete slow : When one of the data is deleted , All the data in the back should be moved to one position .


Using linked list data structure , characteristic , Add and delete quickly , Slow query .

Slow query : The memory address before the element is discontinuous , You can only traverse one by one

increase :

When inserting data , Just change the direction of the memory address ;

Delete the memory address related to it , No one pointed to it , It becomes the object of garbage .

©2019-2020 Toolsou All rights reserved,
Final review of database : Summary of comprehensive application questions Laplance operator ( Second derivative ) Simple learning of computer composition principle pyqt Button call python program _PyQt: Link button to function in program How much can you go up once you change jobs ? Today, I saw the ceiling of job hopping python in str Function usage _python in str Usage Summary of built-in functions MySQL trigger web The server nginx---linux Installation and deployment C++ Chapter V polymorphism exercises :( It's coming to an end )python Check built-in functions , How to check python Built in function