java string.trim 还有 trim "\n" 吗

Does java string.trim also trim "\n" as well

我正在测试 java trim 方法

测试代码:

 public class Main {
    public static void main(String[] args) {
        String t = "testcode\n";        
        System.out.print(t.trim() + "**");              
    }
  }

输出:

testcode**

文档说:

Returns a copy of the string, with leading and trailing white-space omitted

但正如我们所见,它也删除了“\n”

这是预期的行为吗?文档是否具有误导性?

环境:甲骨文java7

是的,\n 被认为是白色的 space,因此 trim() 方法会将其与字符串中任何其他尾随 space 一起删除。