Java String Whitespace Delete deleteWhitespace(String str)

Here you can find the source of deleteWhitespace(String str)

Description

Deletes all whitespaces from a String.

License

Open Source License

Parameter

Parameter Description
str String target to delete whitespace from

Exception

Parameter Description
NullPointerException an exception

Return

the String without whitespaces

Declaration

public static String deleteWhitespace(String str) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* ww w  .j a v a2 s.  co m*/
     * <p>
     * Deletes all whitespaces from a String.
     * </p>
     * 
     * <p>
     * Whitespace is defined by {@link Character#isWhitespace(char)}.
     * </p>
     * 
     * @param str
     *            String target to delete whitespace from
     * @return the String without whitespaces
     * @throws NullPointerException
     */
    public static String deleteWhitespace(String str) {
        StringBuffer buffer = new StringBuffer();
        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                buffer.append(str.charAt(i));
            }
        }
        return buffer.toString();
    }
}

Related

  1. deleteWhitespace(String str)
  2. deleteWhitespace(String str)
  3. deleteWhitespace(String str)
  4. deleteWhitespace(String str)
  5. deleteWhitespace(String str)
  6. deleteWhitespace(String string)
  7. deleteWhitespaces(final String string)
  8. deleteWhiteSpaces(String nodeValue)