String[] list = new String[3];
list[3] = "dog" ;

Answer:

An ArrayIndexOutOfBounds exception is thrown and (usually) the program halts.

ArrayList class

ArrayList object

 

The ArrayList class builds upon the capabilities of arrays. An 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:

  1. The elements of an ArrayList must be object references, not primitive data like int or double.
  2. ArrayList operations are slighly slower than using an array.

The picture uses an "X" to show that a cell is empty. The ArrayList in the picture is completely empty . The "X" is conceptual, only. The actual implementation of ArrayList uses an unspecified means to keep track of empty cells.


QUESTION 4:

(Review: ) Can primitive values, like int be placed into an ArrayList?