String list = new String; list = "dog" ;
ArrayIndexOutOfBounds exception is thrown and
(usually) the program halts.
ArrayList class builds upon the capabilities of arrays.
ArrayList object contains an array of object references
plus many methods for managing that array.
The biggest convenience of a
ArrayList is that you can
keep adding elements to it no matter what size it was originally.
The size of the
ArrayList will automatically increase
and no information will be lost.
However, this convenience comes at a small price:
ArrayListmust be object references, not primitive data like
ArrayListoperations are slighly slower than array operations.
In the picture, "X" shows that a cell is empty.
ArrayList in the picture is completely empty.
The "X" is conceptual;
the actual implementation of
an unspecified means to keep track of empty cells.
(Review: ) Can primitive values, like
int be placed into an