比如我定义一个“hello word”
要求输出“helloword”该怎么办?

解决方案 »

  1.   

    “hello word”.replaceAll(" ", "");
      

  2.   

    public static void main(String[] args)  {
           String a="hello world";
            System.out.print(a.replaceAll(" ", ""));
       }
    或者
       public static void main(String[] args)  {
           String a="hello world";
           char[] b=a.toCharArray();
           for(int i=0;i<b.length;i++){
            if(b[i]==' '){
            continue;
            }
            System.out.print(b[i]);
           }
       }
      

  3.   

    “hello word”.replace(" ", ""); //单纯的去空格OR“hello word”.replaceAll("\\s", ""); //去掉包括TAB,换行之类的空格