Comparison of ArrayList and sort list, And arraylistparts list
ArrayList and collections list are all common implementation methods of the Collection interface. The two adopt an unused storage policy to meet the needs of different occasions.
ArrayList uses a collection to store data.
The only thing to note is that for the processing logic with the capacity exceeding the threshold, the default size of the array is 10, and the maximum capacity is Integer. Max_Value. If the maximum capacity is exceeded, a memory overflow exception is thrown,
For details about the expansion mechanism, refer to the following:
The expanded capacity is 1.5 times the original capacity.
Implementation Method of tranquility list
Two-way linked list nodes are used internally to store data. Because two-way linked lists are used, the shortlist can also be used as stacks and queues, but the efficiency is relatively low. Java provides the efficient implementation of ArrayDeqeue.
In terms of the insert efficiency at the end, the difference between the two is not too large, but the two-way linked list needs to maintain the relationship between the two-way linked list, and the storage efficiency is slightly inferior to that of the ArrayList
ArrayList mainly takes time to expand the capacity and migrate data. If we initialize the capacity at one time, we can also increase the space. Let's take a look at the space for improvement by 50%.
The advantage of Linked lies in the efficiency of header insertion. You only need to modify the pointer of the Header element, and the array also needs to move the subsequent data. All the efficiency is far lower than that of the sorted list.
For get and set operations, the linked list uses binary search, and the array can directly access the element through subscript, so the efficiency is higher than that of the sorted list.
- Based on the above comparison, we can basically determine
If we only store data and perform a simple j iteration, we generally use the set with the highest efficiency,
If frequently modified elements are involved, use the writable list