Comparison of ArrayList and sort list, And arraylistparts list

Source: Internet
Author: User

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.

  • Implementation Method

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.

  • Performance Comparison

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.