title: Why does trim() not remove the trailing white spaces in this example?
body: <p>I am revising Java from here: <a href="http://java-success.blogspot.com.au/2012/06/core-java-coding-questions-frequently.html" rel="nofollow">http://java-success.blogspot.com.au/2012/06/core-java-coding-questions-frequently.html</a> and came along this question:</p>
  
  <p>"Q1. What will be the output of the following code snippet?</p>
  
  <pre><code>String s = " Hello ";
  s += " World ";
  s.trim( );
  System.out.println(s);
  </code></pre>
  
  <p>A1. The output will be</p>
  
  <pre><code>" Hello  World "
  </code></pre>
  
  <p>with the leading and trailing spaces. Some would expect a trimmed "Hello World". </p>
  
  <p>So, what concepts does this question try to test?</p>
  
  <p>String objects are immutable and there is a trick in s.trim( ) line.
  Understanding object references and unreachable objects that are eligible for garbage collection."</p>
  
  <p>Can someone explain why the trailing white spaces are not removed?</p>