[例程]string.trim().length()的用法

public class Test{
    public static void main(String args[]){
        String data = " a bc   ";
        //调用string中的方法trim().length()方法
        int trim = data.trim().length();
        System.out.println("the trim length is "+trim);
       
        int length = data.length();
        System.out.println("the length is "+length);
    }
}

 

 

显示:

 

the trim length is 4

the length is 8

 

trim()方法的作用是去掉字符串头尾的空格.

 

作者:Leo Chin
本博客文章,大多系网络中收集,转载请注明出处

 

posted @ 2015-08-26 16:48  年少初成  阅读(556)  评论(0编辑  收藏  举报