public static String cleanWhitespace(String in){
  char[] inArray=in.toCharArray();
  StringBuffer out=new StringBuffer(inArray.length);
  boolean lastWasSpace=false;
  for (int i=0; i < inArray.length; i++) {
    char c=inArray[i];
    if (Character.isWhitespace(c)) {
      if (!lastWasSpace)       out.append(' ');
      lastWasSpace=true;
    }
 else {
      out.append(c);
      lastWasSpace=false;
    }
  }
  return out.toString();
}

public static String cleanWhitespace ( String in ) { char [ ] inArray = in . toCharArray ( ) ; StringBuffer out = new StringBuffer ( inArray . length ) ; boolean lastWasSpace = false ; for ( int i = 0 ; i < inArray . length ; i ++ ) { char c = inArray [ i ] ; if ( Character . isWhitespace ( c ) ) { if ( ! lastWasSpace ) out . append ( ' ' ) ; lastWasSpace = true ; } else { out . append ( c ) ; lastWasSpace = false ; } } return out . toString ( ) ; }
clean - remove all white spaces
