title: Remove all whitespaces from String but keep ONE newline
body: <p>I have this input String (containg tabs, spaces, linebreaks):</p>
  
  <hr>
  
  <pre><code>        That      is a test.              
      seems to work       pretty good? working.
  
  
  
  
  
  
  
  
      Another test  again.
  </code></pre>
  
  <hr>
  
  <p>[Edit]: I should have provided the String for better testing as stackoverflow removes all special characters (tabs, ...)</p>
  
  <pre><code>String testContent = "\n\t\n\t\t\t\n\t\t\tDas      ist ein Test.\t\t\t  \n\tsoweit scheint das \t\tganze zu? funktionieren.\n\n\n\n\t\t\n\t\t\n\t\t\t      \n\t\t\t      \n    \t\t\t\n    \tNoch ein  Test.\n    \t\n    \t\n    \t";
  </code></pre>
  
  <p>And I want to reach this state:</p>
  
  <hr>
  
  <pre><code>That is a test.
  seems to work pretty good? working.
  Another test again.
  </code></pre>
  
  <hr>
  
  <pre><code>String expectedOutput = "Das ist ein Test.\nsoweit scheint das ganze zu? funktionieren.\nNoch ein Test.\n";
  </code></pre>
  
  <p>Any ideas? Can this be achieved using regexes?</p>
  
  <p><code>replaceAll("\\s+", " ")</code> is NOT what I'm looking for. If this regex would preserve exactly 1 newline of the ones existing it would be perfect.</p>
  
  <p>I have tried this but this seems suboptimal to me...:</p>
  
  <pre><code>BufferedReader bufReader = new BufferedReader(new StringReader(testContent));
  String line = null;
  StringBuilder newString = new StringBuilder();
  while ((line = bufReader.readLine()) != null) {
      String temp = line.replaceAll("\\s+", " ");
      if (!temp.trim().equals("")) {
          newString.append(temp.trim());
          newString.append("\n");
      }
  }
  </code></pre>