Trimming new line character from a string in java

后端 未结 2 1529
逝去的感伤
逝去的感伤 2021-01-19 03:40

The output of below program:

public class TestClass {

    public static void main(final String[] args){
        String token = \"null\\n\";
        token.tr         


        
2条回答
  •  有刺的猬
    2021-01-19 04:34

    Since String is immutable

    token.trim();
    

    doesn't change the underlying value, it returns a new String without the leading and ending whitespace characters. You need to replace your reference

    token = token.trim();
    

提交回复
热议问题