[例程]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
本博客文章,大多系网络中收集,转载请注明出处
原文地址:https://www.cnblogs.com/wangtingyi/p/4760941.html