Identify two benefits of using ArrayList over array in software development.

Identify two benefits of using ArrayList over array in software development.

Identify two benefits of using ArrayList over array in software development.

A.
reduces memory footprint

B.
implements the Collection API

C.
is multi.thread safe

D.
dynamically resizes based on the number of elements in the list

Explanation:
ArrayList supports dynamic arrays that can grow as needed. In Java, standard arrays are of a fixed length. After arrays are created, they cannot grow or shrink, which means that you must know in advance how many elements an array will hold. But, sometimes, you may not know until run time precisely how large of an array you need. To handle this situation, the collections framework defines ArrayList. In essence, an ArrayList is a variable-length array of object references. That is, an ArrayList can dynamically increase or decrease in size. Array lists are created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array may be shrunk.



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Jazz

Jazz

A,D

ArrayList supports dynamic arrays that can grow as needed. In Java, standard
arrays are of a fixed length. An ArrayList is a variable-length array of
object references. That is, an ArrayList can dynamically increase or decrease in size. Array lists are created with an initial size.

James

James

The Answer is A, D.

Note: to use a Java ArrayList to your code, you must first:

import java.util.ArrayList;

Also, the initial capacity for an ArrayList when not specified is 10.

The initial capacity of a StringBuilder object is 16, when not specified.

James

James

Also, there is a difference between the size and capacity of an ArrayList:

* The size of an ArrayList is the number of elements in the list.
* The capacity of an ArrayList is how many elements the list can potentially accommodate without reallocating its internal structures.

Hans

Hans

What about B? ArrayList is one of the most widely used classes from the Collections framework accoirding to Mala Gupta in OCA java SE7 certification guide.;