java face questions of ArrayList

Arraylist insert delete speed must slow it?

Delete: This depends on the elements to be deleted from the array end how far, if from a distance, then you find that this element corresponding index will slow, slow query if the index is then deleted speed will be slower.
Insert: insert look at the situation:

There is a defined variable size Arraylist length
condition: if ArrayList length of the array corresponding to the bottom is exactly divisible then be 1.5 then we must initialize the length of the underlying array, a new array which requires new waste of time
1) into the end : If the condition is not satisfied is then inserted directly into the array size ++ gets the job done
2) inserted into the specified location: If the condition is not satisfied, then also need to engage in a new array to store, combining a waste of time traversing the original array

How is ArrayList expansion?

ArrayList during initialization initializes the length of the bottom of the array 16 for data storage ArrayList, and every time data is recorded inserted ArrayList of size, if the size is greater than 10 ArrayList, a new array will be new, which the original length of the new group is 1.5 times the original array and copied to the new array, this is a waste of time, so we generally give ArrayList specified size.

Published 69 original articles · won praise 6 · views 2494

Guess you like

Origin blog.csdn.net/qq_40539437/article/details/104044325