例如,str="hello_yyo___koko__!!!";
   newStr="hello_yyo_koko_!!!";

解决方案 »

  1.   

    用replaceAll,当然,还有正则
    代码如下:public class BlankTest {
        public static void main(String[] args) {
            System.out.println(deleteMulBlank("hello yyo    koko  !!!"));
            System.out.println(deleteMulBlank("afsaf    fdsfdf   fsdfsdf fs fs dfsdfsfsdf sdfsdfsdf sdfsdf sd fs f sdf sdf sdfd"));
        }
        
        public static String deleteMulBlank(String str){
            return str.replaceAll("[ ]{2,}", " ");
        }
    }
      

  2.   

    正则不就能处理了?
    String.replaceAll("// *"," ");
      

  3.   


    你要的是不是这个trim()方法,返回值是String
      

  4.   

    在JAVA当中就没有指针,如果说有那就是引用了。
    呵呵。你搞错了吧。是不是要把下划线换成空串进行连接吧。
    以下是我写好的代码你可以参考一下。
    --------------------------------------------------------
    String str="fsdfs_fsdfsdf_fsd";
    Pattern p=Pattern.compile("_");
    Matcher m=p.matcher(str);
    str=m.replaceAll("");
    System.out.println(str);