title: Correct way to trim a string in Java
body: <p>In Java, I am doing this to trim a string: </p>
  
  <pre><code>String input = " some Thing ";
  System.out.println("before-&gt;&gt;"+input+"&lt;&lt;-");
  input = input.trim();
  System.out.println("after-&gt;&gt;"+input+"&lt;&lt;-");
  </code></pre>
  
  <p>Output is: </p>
  
  <pre><code>before-&gt;&gt; some Thing &lt;&lt;-
  after-&gt;&gt;some Thing&lt;&lt;-
  </code></pre>
  
  <p>Works. But I wonder if by assigning a variable to itself, I am doing the right thing. I don't want to waste resources by creating another variable and assigning the trimmed value to it. I would like to perform the trim in-place.</p>
  
  <p>So am I doing this right?</p>