[Java Basics] The difference between ArrayList and LinkedList and the usage scene

Source: Internet
Author: User

First of all, ArrayList and LinkedList are common container classes in Java, all implement the list interface, but because the data structure is different when implementing the list interface, there are differences in their usage.

Here's a summary:

1. ArrayList is an array-based linear table, except that it can be dynamically extended. If you do not specify a ArrayList initial capacity value, it takes the default value of 10, and if you add an object reference to the ArrayList, it will automatically expand when it is not already accommodated, and the coefficient of expansion is 1.5;

2. ArrayList is very fast for searching by index value, and the time Complexity is O (1); However, for the insertion and deletion of redundant mobile copies of the consumption of processing, the time complexity of O (n);

3. LinkedList is a list interface based on the data structure of the doubly linked list, so the execution efficiency of the lookup is low and the time complexity is O (n).

4. LinkedList for insertion and deletion, the execution efficiency is high, the time complexity is O (1);

5. From the storage point of view, LinkedList than ArrayList memory consumption is higher, because each node needs to have an extra two nodes of the reference to represent;

Note: Limited capacity, if there are errors, please advise!

[Java Basics] The difference between ArrayList and LinkedList and the usage scene

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.