trim() 方法是否也删除 CRLF 字符?

Does trim() method removes CRLF characters also?

突然注意到 trim() 方法删除了 CRLF - 新行 - 字符也..:[=​​13=]

String s = "str\r\n";
s = s.trim();

System.out.println("--");
System.out.print(s);
System.out.println("--");

是故意的吗?

是的,见 doc:

Otherwise, let k be the index of the first character in the string whose code is greater than '\u0020', and let m be the index of the last character in the string whose code is greater than '\u0020'. A new String object is created, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m+1).

CR+LF: CR (U+000D) followed by LF (U+000A)小于U+0020