value.trim()解释下是什么意思呢?
就是字符串去除字符串最左边和最右边的空格
如String i = new String(" 123 123 ");//字符串最左边,最右边以及中间各有2个空格
System.out.println(i);
System.out.println(i.length());
System.out.println(i.trim());
System.out.println(i.trim().length());
输出的结果为:
123 132
12
8
123 132
因为trim()方法去除了字符串最左边,最右边的空格,所以字符串长度少了4,
注:trim()方法无法去除字符串中间的空格
The java string trim() method eliminates leading and trailing spaces. The unicode value of space character is '\u0020'. The trim() method in java string checks this unicode value before and after the string, if it exists then removes the spaces and returns the omitted string.