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()方法的作用是去掉字符串头尾的空格

原文地址:https://www.cnblogs.com/yangyi9343/p/5736871.html