Trim method removes the white space characters at both ends of the string. There are some questions about the return value. Why do you have to judge the subscript? I understand that no matter whether the string has blank characters or not, you can return the substring.
public String trim() {
int len = value.length;
int st = 0;
char[] val = value; /* avoid getfield opcode */
while ((st < len) && (val[st] <= " ")) {
stPP;
}
while ((st < len) && (val[len - 1] <= " ")) {
len--;
}
return ((st > 0) || (len < value.length)) ? substring(st, len) : this;
}
finally, return is not very understanding, ask for help, thank you ~!