Character 'I' (the beginning character of the string).
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.
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.
What does the following code write?
String myString = null; System.out.println("The length is: " + myString.length() )