
In this case, the capacity of listOfAstronauts1 is 5 and its size is 0.
We can also combine the declaration and instantiation of an ArrayList
object into one statement. Here is the syntax using the default constructor:
ArrayList<ClassName> arrayListName = new ArrayList<ClassName>( );
These statements will declare and instantiate two ArrayList objects, Integers
and Astronauts, respectively:
ArrayList<Integer> listOfInts = new ArrayList<Integer>( );
ArrayList<Astronaut> listOfAstronauts2 = new ArrayList<Astronaut>( );
9.7.2 Methods of the ArrayList Class
Like arrays, the ArrayList class uses indexes to refer to elements. Among
others, it provides methods ...