1.去掉首尾空格:String.trim();
2.去掉首尾、中間所有空格:String str1 = str.replaceAll(" ", ""); 或replaceAll(" +","");
3.去掉大部分空白字元, 不僅僅是空格:String str2= str.replaceAll("\\s*", "");
1.去掉首尾空格:String.trim();
2.去掉首尾、中間所有空格:String str1 = str.replaceAll(" ", ""); 或replaceAll(" +","");
3.去掉大部分空白字元, 不僅僅是空格:String str2= str.replaceAll("\\s*", "");