trim() only removes leading and trailing spaces, to remove the internal spaces, you have to use indexOf() to find the spaces and then construct a new string from substrings before and after the spaces....if you are using jdk1.4, you can use the new Regular Expressions classes: java.util.regex.*;

解决方案 »

  1.   

    可以先定义一个临时string  temp
    然后从源string的第一个字符开始一个字符一个字符的copy到temp中
    copy的时候首先判断该字符时候为blank  如果不是才拷贝到temp中
      

  2.   

    trim()只能去掉头和尾的空格自己写个method...
      

  3.   

    replace():
    能替换一个字符为另一个字符,但2个字符需等长。此法可把@换成a,但不能去掉@。
    trim():
    如楼上所言,只能去掉头和尾的空格
    String string2=new String();
    for(int i=1;i<=String1.length;i++)
    {
    if(!String1.substring(i,i+1).equals("@")){
    string2=string2+String1.substring(i,i+1)
    }
    }
    匆忙之中未检查,自己调试一下