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