More about Strings

This chapter accompanies the previous one. Read it for even more info on Strings.

4. String Indexing


Character 'I' (the beginning character of the string).

String Indexing

The beginning character of a string corresponds to index 0 and the last character corresponds to the index (length of string)-1.


The length of a string is the number of characters it contains, including spaces, punctuation, and control characters. Fill in the following table by clicking on the buttons.

"buttons and bows".length()

The sequence \t stands for a single character, a tab character. Each tab character counts as one character (although it might be displayed on a monitor or printer using several spaces).

Be careful about the difference between an empty string, and a null reference. An empty string is an object that contains no characters, and so has length 0. A null reference means there is no object present.

Question 4:

What does the following code write?

    String myString = null; System.out.println("The length is: " + myString.length() )