This method removes whitespace characters from both sides
Principle:
See the source code implementation
PublicString Trim () {intLen =value.length; intSt =0; Char[] val = value;/*avoid GetField opcode*/ while(St < Len) && (Val[st] <=' ') ) {St++; } while(St < Len) && (Val[len-1] <=' ') ) {len--; } return(St >0) || (Len < value.length)) ? SUBSTRING (ST, Len): This; }View Code
According to the source, the string is split into a character array, and then the ASCII code of the characters from both ends of the character array is compared to the ASCII code of the space character, then the first start and the last (inclusive) characters greater than 32 are taken.
Attached: integer.valueof ("); The ASCII code that can view the space is ASCII code of 32,TAB is 9.
Extension: the definition of whitespace in Java
The. Trim () method of String in Java