62,614
社区成员
发帖
与我相关
我的任务
分享
String str = "language Specification";
String str2 = str.replaceAll(" ", "");
System.out.println(str2);
String str = "language Specification"; //要去空格的字符串
String str2 = ""; //去空格后的字符串
String[] str1 = str.split(" "); //把原字符串按空格分割
for(int i = 0;i<str1.length;i++)
{
if(str1[i] != "")
{
str2 += str1[i]; //
}
}
System.out.println(str2);
str = .replaceAll("\\s*", "");
str = str.replaceAll(" ","");
public String remove(String resource,char ch)
{
StringBuffer buffer=new StringBuffer();
int position=0;
char currentChar;
while(position<resource.length())
{
currentChar=resource.charAt(position++);
if(currentChar!=ch) buffer.append(currentChar);
}
return buffer.toString();
}