go to previous page   go to home page   go to next page

Must all the Strings be of the same length?

Answer:

No. Each element of the array is of the same type a reference to a String, but the Strings themselves can be of different lengths.


Each String Object Holds its own Data

array of string references

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" ;

QUESTION 5:

Assign a reference to the string "the end" to the last cell of the array.