Array and arraylist

Source: Internet
Author: User
What are the practical advantages of arraylist?

Number of questions: 20. replies: 8

Singles' INE (Hill) on the first floor replied to the score of 10 at 15:57:25 on
Arraylist is a complex version of an array. The arraylist class provides some functions that are provided in most collections classes but not in the array class. For example:

The array capacity is fixed, and the arraylist capacity is automatically expanded as needed. If the value of the arraylist. Capacity attribute is changed, memory reallocation and element replication are performed automatically.
Arraylist allows you to add, insert, or remove a range of elements. In array, you can only get or set the value of one element at a time.
Using synchronized, you can easily create a synchronization version of arraylist. Array will keep it until the user achieves synchronization.
Arraylist provides a method to return read-only and fixed-size packages to a set. Array does not.
On the other hand, array provides some flexibility that arraylist does not have. For example:

You can set the lower limit of array, but the lower limit of arraylist is always zero.
Array can have multiple dimensions, while arraylist is always one-dimensional.
Array of a specific type (excluding objects) has better performance than arraylist. This is because the elements of arraylist belong to the object type. Therefore, when storing or retrieving value types, binning and unboxing are usually generated.
In most cases, an array can be replaced by arraylist. It is easier to use and generally has the same performance as an array of the object type.

Array is in the system namespace; arraylist is in the system. Collections namespace

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.