Is “new String()” immutable as well?

后端 未结 15 2494
日久生厌
日久生厌 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-13 00:00

    String is immutable because it does not provide you with a mean to modify it. It is design to avoid any tampering (it is final, the underlying array is not supposed to be touched ...).

    Identically, Integer is immutable, because there is no way to modify it.

    It does not matter how you create it.

提交回复
热议问题