Will the following statement make the array larger?

list = new String[5];

A good answer might be:

No. The statement creates a completely new array object (with room for 5 slots). All the information in the old array object is now garbage.


Old Information is Lost

In the example, the reference variable list is set to the newly constructed object. The information in the old object is not automatically transferred. To keep the old information, the program would have to copy it to a new array after it was constructed. This is not too hard, but it is a nuisance.

In the diagram, the diagonal slashes represent null, the value a reference has when it refers to no object.


QUESTION 3:

What happens if information is added to an array slot that does not exist?

String[] list = new String[3];
list[0] = "ant" ;
list[1] = "bat" ;
list[2] = "cat" ;

list[3] = "dog" ;