I have a string:
As stated in the Javadoc for
Returns a copy of the string, with leading and trailing whitespace omitted.
String is not modified (
Strings are immutable in Java). So you need to use the object returned after calling
// Assuming you have stored the orginial String in a variable called 'myString' myString = myString.trim (); System.out.print (myString.charAt(4)); // or System.out.print (myString.trim ().charAt(4));