go to previous page   go to home page   go to next page

Answer:

ArrayList<Student> students = new ArrayList<Student>( 30 );

A rough estimate for the capacity is good enough. It is better to overestimate it than to underestimate it. A few unused cells do not hurt.


Capacity and Size

ArrayList after three add operations

An ArrayList object has a capacity and a size.

The size increases by one each time an element is added. However, the capacity remains unchanged until the ArrayList is full. When an element is added to a full list, the Java runtime system will greatly increase the capacity of the list so that many more elements can be added.

To find out the current size of an ArrayList use its size() method.


QUESTION 8:

What is the capacity of the ArrayList in the picture?

What is its size?