java中string.trim()函数的使用

trim():去掉字符串首尾的空格。

 

public static void main(String arg[]){
 
        String a=" hello world ";
 
        String b="hello world";
 
        System.out.println(b.equals(a));
 
        a=a.trim();//去掉字符串首尾的空格
 
        System.out.println(a.equals(b));
    }
执行结果:
a: hello world  ,false
a:hello world,true

 

猜你喜欢

转载自blog.csdn.net/qq_36932624/article/details/83026540