【发布时间】:2013-09-24 19:02:54
【问题描述】:
以下程序的输出:
public class TestClass {
public static void main(final String[] args){
String token = "null\n";
token.trim();
System.out.println("*");
System.out.println(token);
System.out.println("*");
}
}
是:
*
null
*
然而
How to remove newlines from beginning and end of a string (Java)?
另有说法。
我错过了什么?
【问题讨论】:
-
字符串是不可变的......阅读修剪文档
-
您所指问题的已接受答案显示了 trim() btw 的正确用法...
-
@All:对不起,我的错误..请不要投反对票! :( :(