字符串以'\n'结尾以什么是最有效的操作方式?

yoa*_*str 0 java string android

碰巧用户点击输入我不希望将其包含在我输入的一部分中,字符串可以以3次结束\n所以只需替换一个不会完成我的解决方案的工作;

String values[] = string_Ends_With_Back_Slash_N.split("\n"); 
String String_without_Back_Slash_N =new String (values [0]);
//or just to point there without the new but i want later to dump the garbage.
Run Code Online (Sandbox Code Playgroud)

或者至少现在将值转储到gc ....

所以两个q:

  1. 有更有效的方式吗?..
  2. 谁我称之为编译器(java on android ...)

Boz*_*zho 5

尝试 String.trim()

此方法从String的末尾删除所有字符,其中ascii代码小于空格(interval,32).这包括\n(10).