public class StringUtil
{
public static void replaceBlank()
{
Pattern p = Pattern.compile(“\\s*|\t|\r|\n”);
String str="I am a, I am Hello ok, \n new line ffdsa!";
System.out.println("before:"+str);
Matcher m = p.matcher(str);
String after = m.replaceAll("");
System.out.println("after:"+after);
}
public static void main(String[] args)
{
replaceBlank();
}
}
http://hi.baidu.com/mutourenoo/blog/item/c41f2c6e3be7cad381cb4a9c.html