[例程]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()方法的作用是去掉字符串头尾的空格.
欢迎访问:wenhao.ink