Java tutorial
//package com.java2s; public class Main { public static final String EMPTY_STRING = ""; public static final String REGEX_WHITESPACE = "\\s"; /** * Strips a string of all white space and replaces with an empty string. * * @param original string that can have any number of spaces. * @return a clean string stripped of white space. */ public static String getCleanString(String original) { if (original == null || original.isEmpty()) { return EMPTY_STRING; } return original.replaceAll(REGEX_WHITESPACE, EMPTY_STRING); } }