string.trim().length()的用法

 1 public class Test{
 2     public static void main(String args[]){
 3         String data = " a bc   ";
 4         //调用string中的方法trim().length()方法
 5         int trim = data.trim().length();
 6         System.out.println("the trim length is "+trim);
 7         
 8         int length = data.length();
 9         System.out.println("the length is "+length);
10     }
11 }

 

显示:

the trim length is 4
the length is 8

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

posted on 2016-08-04 15:26  临界  阅读(1120)  评论(0编辑  收藏  举报