Is “new String()” immutable as well?

后端 未结 15 2530
日久生厌
日久生厌 2020-12-12 23:43

I\'ve been studying Java String for a while. The following questions are based on the below posts

Java String is special
Immutability of String in java

15条回答
  •  难免孤独
    2020-12-12 23:58

     String A = "Test"
     String B = "Test"
    

    Now String B called"Test".toUpperCase()which change the same object into"TEST", soAwill also be"TEST"` which is not desirable.

提交回复
热议问题