public String trim() {
int len = count;
int st = 0;
int off = offset;      /* avoid getfield opcode */
char[] val = value;    /* avoid getfield opcode */ while ((st < len) && (val[off + st] <= ' ')) {
    st++;
}
while ((st < len) && (val[off + len - 1] <= ' ')) {
    len--;
}
return ((st > 0) || (len < count)) ? substring(st, len) : this;
    }为什么是<= ' ';而不是看是不是和' '相同字符

解决方案 »

  1.   

    规范问题吧,貌似认为小于等于空格的都是不可见字符,都是被trim的对象.
      

  2.   

    就是去掉小于或等于 \u0020(空格)的字符根据 API DOC 上的说明,在使用 trim 后字符串的首尾的字符都应大于 \u0020
      

  3.   

    4,5楼错了。
    等于只能trim掉' ',其它非可见字符如换行、tab、回车等就无法去除了