public static String cleanWhitespace(String str) {
        int length = str.length();

        StringBuffer buf = new StringBuffer(length);
        for (int i=0; i<length; i++) {
            char c = str.charAt(i);
            if (Character.isWhitespace(c)) {
                buf.append(' ');
            }
            else {
                buf.append(c);
            }
        }

        return buf.toString();
    }
public static String cleanWhitespace ( String str ) { int length = str . length ( ) ; StringBuffer buf = new StringBuffer ( length ) ; for ( int i = 0 ; i < length ; i ++ ) { char c = str . charAt ( i ) ; if ( Character . isWhitespace ( c ) ) { buf . append ( ' ' ) ; } else { buf . append ( c ) ; } } return buf . toString ( ) ; }
Converts all whitespace characters in a String to space characters
(\u0020).