剔除字符串中所有的空格
package com.senchen365.dateConstruct;
/**
* 类名:TrimAll<br>
* 作者:java菜鸟<br>
* 功能:实现剔除所有的空格<br>
* 时间:16:46<br>
* 版本:1.0.0<br>
*/
public class TrimAll {
public static void main(String[] args){
String str = " 1 + 2 * 3 - 4 + 5 ";
if (str == null || str.length() <= 0 || str.trim().equals("")){
System.out.println("输入不合法");
return;
}
StringBuilder strB = new StringBuilder(str);
int j = 0;
for (int i = 0; i <= strB.length() - 1; i++ ) {
if (strB.charAt(i) != ' '){
strB.setCharAt(j,strB.charAt(i));
j++;
}
}
strB.setLength(j);
System.out.println(strB);
}
}