Correct way to trim a string in Java

后端 未结 8 885
独厮守ぢ
独厮守ぢ 2020-12-15 04:30

In Java, I am doing this to trim a string:

String input = \" some Thing \";
System.out.println(\"before->>\"+input+\"<<-\");
input = input.trim(         


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 04:40

    Yes, but there will still be two objects until the garbage collector removes the original value that input was pointing to. Strings in Java are immutable. Here is a good explanation: Immutability of Strings in Java.

提交回复
热议问题