public static String collapseWhitespace(String str){
  return str.replaceAll("\\s+"," ");
}

public static String collapseWhitespace ( String str ) { return str . replaceAll ( "\\s+" , " " ) ; }
replaces all sequences of whitespace by a single blank .
