Java-preliminary Understanding-Common Object API (collection framework-arrays and linked lists)

Source: Internet
Author: User

One.

Focus on the ArrayList and LinkedList query the reasons for the speed, both additions and deletions have been introduced.

The array is a contiguous space, placed in the heap memory, and the elements are placed inside the array.

Explain why queries for arrays are fast (all relative) and why the list queries are slow.

In heap memory, much of the data is randomly placed, but if a part is stored as an array, it is stored in a corner label. Querying on successive sections is faster than searching in many random locations. However, if it is additions and deletions, then the operation of the array is reaching, the whole is to be adjusted, because the array is as a whole to appear.

The following shows the memory distribution of the linked list structure, the reason why the deletion is fast is shown below, but the 98-point element is still in memory, but not in the list structure. Why is the list structure query slow, because the overall memory is not a list structure, or loose. Therefore, the query is relatively slow (in fact, some of them do not speak).

Does the element in the LinkedList have a corner mark? It is a sub-class of the list interface, the most important feature of the list interface is the corner label, its subclass is all.

The array is a contiguous space, plus numbering. The list is not a continuous space, it is also labeled. It is said here that continuity and discontinuity may be said to mean the distribution. The list distribution may not be contiguous, although the links are together.

Java-preliminary Understanding-Common Object API (collection framework-arrays and linked lists)

Related Article

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.