strArray[1] = "World" ;
Recall these facts about all arrays:
String
".
Frequent Bug: It is easy to confuse the length of an array with the number
of cells that contain a reference.
In the example, only two cells contain references to String
s, but
strArray.length
will be 8.
Here is a section of code that declares and constructs the array, and puts
some more String
s into it:
String[] strArray = new String[8] ; // combined statement strArray[0] = "Hello" ; strArray[1] = "World" ; strArray[2] = "Greetings" ; strArray[3] = "Jupiter" ;
Must all the String
s in the array be of the same length?