The difference between LinkedList and arrarylist. <java>

Source: Internet
Author: User

LinkedList are stored with dynamic lists, while ArrayList are stored in dynamic arrays.

First, if the array to query, set up, and so on, with ArrayList faster, the method is get () and set ().

Second, if the data to increase, move and other operations, with LinkedList relatively fast, the method has a large () and remove ().

There is a private class in LinkedList, as follows:

Private static class Entry {

Object element; Element value

Entry Next; Next pointer address

Entry previous; Previous pointer address

}

When you add or remove elements, entry next of the last pointer refers to the new position, and the pointer to the newly added element entry previous to the last element. However, there is a certain amount of waste to memory because the front and back pointers are always stored.

For ArrayList, the movement of data is involved, especially if the first element is added or deleted, then all the remaining arrays move. The increase is likely to result in the expansion of the array, each expansion of about 50%, the formula for the new total capacity = (/2+1 old capacity).

Third, LinkedList does not support efficient random element access.

The difference between LinkedList and arrarylist. <java>

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.