Removing whitespace from strings in Java

前端 未结 30 2197
一个人的身影
一个人的身影 2020-11-22 05:01

I have a string like this:

mysz = \"name=john age=13 year=2001\";

I want to remove the whitespaces in the string. I tried trim()

30条回答
  •  迷失自我
    2020-11-22 05:39

    public static void main(String[] args) {        
        String s = "name=john age=13 year=2001";
        String t = s.replaceAll(" ", "");
        System.out.println("s: " + s + ", t: " + t);
    }
    
    Output:
    s: name=john age=13 year=2001, t: name=johnage=13year=2001
    

提交回复
热议问题