cdm/src/main/java/ucar/unidata/util/StringUtil2.java
static public String collapseWhitespace(String s) {
    int len = s.length();
    StringBuilder b = new StringBuilder(len);
    for (int i = 0; i < len; i++) {
      char c = s.charAt(i);
      if (!Character.isWhitespace(c)) {
        b.append(c);
      } else {
        b.append(' ');
        while ((i + 1 < len) && Character.isWhitespace(s.charAt(i + 1))) {
          i++;  /// skip further whitespace
        }
      }
    }
    return b.toString();
  }
static public String collapseWhitespace(String s) {
    int len = s.length();
    StringBuilder b = new StringBuilder(len);
    for (int i = 0; i < len; i++) {
      char c = s.charAt(i);
      if (!Character.isWhitespace(c)) {
        b.append(c);
      } else {
        b.append(' ');
        while ((i + 1 < len) && Character.isWhitespace(s.charAt(i + 1))) {
          i++;  /// skip further whitespace
        }
      }
    }
    return b.toString();
  }
static public String collapseWhitespace ( String s ) { int len = s . length ( ) ; StringBuilder b = new StringBuilder ( len ) ; for ( int i = 0 ; i < len ; i ++ ) { char c = s . charAt ( i ) ; if ( ! Character . isWhitespace ( c ) ) { b . append ( c ) ; } else { b . append ( ' ' ) ; while ( ( i + 1 < len ) && Character . isWhitespace ( s . charAt ( i + 1 ) ) ) { i ++ ; /// skip further whitespace
 } } } return b . toString ( ) ; }
Collapse continuous whitespace into one single " ".

@param s operate on this string
@return result with collapsed whitespace
Collapse continuous whitespace into one single .