Trimming new line character from a string in java

后端 未结 2 1530
逝去的感伤
逝去的感伤 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:26

    Strings are immutable. Change

    token.trim();
    

    to

    token = token.trim();
    
    0 讨论(0)
  • 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();
    
    0 讨论(0)
提交回复
热议问题