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

posted @ 2011-11-17 14:36  hnrainll  阅读(4745)  评论(0编辑  收藏  举报