text: I tried the following code snippet
  public class StringCheck {
  public static void main(String args[]) {
  String s = "SCJA ";
  System.out.println(s.length());
  s.trim();
  s = s + "Exam";
  System.out.println(s);
  }
  The o/p of the code is SCJA Exam. Trim() method of String suppose to the remove the trailing spaces at the end of the sting. But it isn't the case here, I tried to run this code in Eclipse.
  Any clarification would be greatly appreciated.
  Saloon Keeper
  So, with trim(), the String on which the method is called is left alone, but a new String is returned.
  Here's a quick snippet from the SCJA Certification Guide:
  When character Strings are fed from a user interface, into a programming model, the Strings are often filled with all sorts of trailing whitespace, also known as blank characters, that serve no purpose, and only take up space in memory, and on the hard drive when physically stored. The trim() method creates a new String, with all leading and trailing whitespace removed and getting rid of redundant whitespace will make your programs more efficient.
  It is important to note that the trim() method trims off both leading and trailing whitespace, and it returns a new, trimmed String, without changing the String on which the method is originally invoked.
  From your original code, I believe the following two code snippets would produce the results in which you are interested:
  Code Snippet 1:
  Code Snippet 2:
  Here's the definition from Sun's Site
  JavaDoc for java.lang.String, the Trim method
  trim
  public String trim()
  Returns.
  Returns:
  A copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.
  -Cameron McKenzie
  [ March 11, 2007: Message edited by: Cameron W. McKenzie ]
  Originally posted by Cameron W. McKenzie:
  ...it doesn't trim the length of the String on which it is invoked, but instead, returns a new String with the length trimmed. The immutability of the String class pretty much forces this I guess...
  Right. Strings are immutable, so you're never really modifying a String object. Instead, methods like this create a new String and return a reference to the new String.
  So when invoking these methods, you need to assign that return value to some variable (often the same variable that referenced the original String). Otherwise, the new String is created, but you will have no way to reach it.
  [ March 12, 2007: Message edited by: marc weber ]
  