Will the following statement make the array larger?
list = new String[5];
No. The statement creates a completely new array object (with 5 cells). The old array object is now garbage, unless some other reference variable points to it.
In the example,
the reference variable list
is set to the
newly constructed object.
The diagram shows what happens. The diagonal slashes represent
null, the value that means "no object".
The information in the old object is not transferred to the new object. 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.
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" ;