title: Java how to replace 2 or more spaces with single space in string and delete leading and trailing spaces
body: <p>Looking for quick, simple way in Java to change this string </p>
  
  <pre><code>" hello     there   "
  </code></pre>
  
  <p>to something that looks like this</p>
  
  <pre><code>"hello there"
  </code></pre>
  
  <p>where I replace all those multiple spaces with a single space, except I also want the one or more spaces at the beginning of string to be gone.</p>
  
  <p>Something like this gets me partly there</p>
  
  <pre><code>String mytext = " hello     there   ";
  mytext = mytext.replaceAll("( )+", " ");
  </code></pre>
  
  <p>but not quite.</p>