Here you can find the source of deleteWhitespace(String str)
Deletes all whitespaces from a String.
Parameter | Description |
---|---|
str | String target to delete whitespace from |
Parameter | Description |
---|---|
NullPointerException | an exception |
public static String deleteWhitespace(String str)
//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(); } }