Differences between ArrayList and javaslist and code parsing in use scenarios,

Source: Internet
Author: User

Differences between ArrayList and javaslist and code parsing in use scenarios,

This article focuses on the differences between ArrayList and javaslist in Java programming and related content in use scenarios. The specific introduction is as follows.

1. ArrayList is implemented based on arrays. Its constructor is:

Private transient Object [] elementData; private int size;

During ArryList initialization, the default elementData array size is 10;
Each time you add (), call ensureCapacity () to ensure that the array will not overflow. If it is full, it will be expanded to 1.5 times of the array length + 1, and then use array. copy the original array to the new array;
The ArrayList thread is not secure. The Vector method is synchronous and the thread is secure;

2. The explain list is implemented based on double-stranded tables:

Object element; Entry next, previous;

During initialization, there is a header Entry with a value of null;

The advantage of using header is that there is a front entry and a rear entry in any entry (including the first and last one, therefore, there is no special place for the insert operation at the beginning or end of the listing list object;

Use Cases:

(1) If the application accesses or deletes a large number of elements at each index location, the ArrayList object is far better than the partial list object;

(2) If the application mainly loops the list and inserts or deletes the list during the loop, the sorted list object is far better than the ArrayList object.

Summary

The above is all about the differences between ArrayList and javaslist and the use case code parsing. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

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.