The index of the first character of a
String is zero and the index of the last character (if I am not wrong,) is length of the String minus one.
Using charAt():
Prints:
Length of str is 5
Character at zero position is H
Last character is o
The above code throws StringIndexOutOfBoundsException, because when the index starts with zero the last element would be at position length of the string minus one.
Using getChars():
Prints:
Hell<junk here>
Hello
Why is the last character that the line marked "Line 1" contain junk and why is the line marked "Line 2" not throw an Exception?
Kezia.