An Immutable String
Strings are immutable,
you can safely give this answer even though you don't know
String has been constructed,
you know what is in it.
charAt(int index) method of
returns the character at the specified index.
Index 0 is the first character of the
and the last character is at index
String eg = "An Immutable String"; char ch0 = eg.charAt(0); // ch0 gets 'A' char ch1 = eg.charAt(1); // ch1 gets 'n' char ch5 = eg.charAt(5); // ch5 gets 'm' char ch18 = eg.charAt( eg.length()-1 ); // ch18 gets 'g' char ch17 = eg.charAt( eg.length()-2 ); // ch17 gets 'n'
Notice that the method returns a value of type
(Design Question: ) How could you make a string that contains the characters of another string in reverse order?