The realization principle of ArrayList

Source: Internet
Author: User

ArrayList is an implementation of a mutable array of list interfaces. Implements all optional list operations and includes all elements, including null values. This class also provides methods to manipulate the size of the array used internally to store the list.

ArrayList is achieved by:

For ArrayList, he implements the list interface, the underlying use of arrays to save all elements, the operation is basically an array of operations.

LinkedList implements the list interface, but it performs and inserts operations more efficiently than ArrayList, because it is based on a linked list and also determines that it is less than ArrayList in terms of random access .

In addition, Linkedlis provides methods that can be used as stacks, queues, and double-ended queues, in which the names differ from each other, so that they are more appropriate in a particular context. 、

ArrayList(Fast to access, slow to modify) the underlying use of array elements, the size of the array is self-increasing, (insert element, because the array capacity is not known, the array is copied to a new array,).

LinkedList (Fast check slow) is the bottom of the list, through the node directly connect elements, each node contains the reference of the front and back nodes and the values stored by the node,

When modifying, insert a new element, only need to modify the reference relationship of the front and back nodes,

But access is, to traverse the node to locate, so the access speed is slow.

The realization principle of ArrayList

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.