Java中除去字符串中的所有空格

Java中去除字符串中的所有空格String str hell o String str2 str.replaceAll( , )System.ou

Java中去除字符串中的所有空格
 
String str = " hell o "; 
String str2 = str.replaceAll(" ", ""); 
System.out.println(str2); 
 
  
 
3.或者replaceAll(" +",""); 去掉所有空格 
 
  
 
4.str = .replaceAll("\\s*", ""); 
 
可以替换大部分空白字符, 不限于空格  
\s 可以匹配空格、制表符、换页符等空白字符的其中任意一个