title: remove extra white space and invisible chars from string using java
body: <p>I have a big conversation, I am handling it as String in between the string there are many white spaces may be invisible non word characters also. 
  Below is an example string:</p>
  
  <pre><code>public static void main(String[] args) {
    String str = " TWD day count Spot                              6-Sep / 2-Sep 2016 1W7d                        13-Sep / 9-Sep 2016 1M30d                      6-Oct / 4-Oct 2016 2M62d                      7-Nov / 3-Nov 2016 3M91d                      6-Dec / 2-Dec 2016 6M181d                    6-Mar / 2-Mar 2017 9M273d                    6-Jun / 2-Jun 2017 12M365d                  6-Sep / 4-Sep 2017 18M546d                  6-Mar / 2-Mar 2018 24M730d                  6-Sep / 4-Sep 2018";
    str = str.toString().replaceAll(" +", "");
    System.out.println("str="+str.toString().trim().replaceAll(" ", ""));
  }
  </code></pre>
  
  <p>I tried many string functions to remove white spaces like <code>trim()</code>, <code>replaceAll(" ","")</code>, <code>replaceAll("\\s","")</code>, <code>replaceAll(" +","")</code>, <code>replaceAll("\\s\\u00a0","")</code>, <code>stringUtils.normalize()</code> function etc. Many I tried but not working as expected. </p>
  
  <p>I am expecting the output as below:</p>
  
  <blockquote>
    <p>"String str = " TWD day count Spot 6-Sep / 2-Sep 2016 1W7d 13-Sep /
    9-Sep 2016 1M30d 6-Oct / 4-Oct 2016 2M62d 7-Nov / 3-Nov 2016
    3M91d 6-Dec / 2-Dec 2016 6M181d 6-Mar / 2-Mar 2017 9M273d "</p>
  </blockquote>
  
  <p>Just one space instead of long white duplicate spaces. </p>
  
  <p>Please help.</p>
  
  <p>Found the answer as below:</p>
  
  <pre><code>System.out.println("str="+str.replaceAll("(?U)\\s+", " "));
  </code></pre>