Must all the Strings be of the same length?
No. Each element of the array is of the same type:
a reference to a String
.
Each reference can point to a different String
object
each with its own length.
Each String
object in the example is an ordinary String
.
Nothing about it has changed because its reference
is held in an array.
Each String
can have any number of characters.
The picture shows this.
There is no requirement to fill the array in order. Often this is done to make further work easier, but Java does not require it.
String[] strArray = new String[8] ; strArray[0] = "Hello" ; strArray[1] = "World" ; strArray[2] = "Greetings" ; strArray[3] = "Jupiter" ;
Assign a reference to the string "the end" to the last cell of the array.