How should I copy Strings in Java?

前端 未结 5 1884
遥遥无期
遥遥无期 2020-12-12 14:14
    String s = \"hello\";
    String backup_of_s = s;
    s = \"bye\";

At this point, the backup variable still contains the original value \"hello

5条回答
  •  醉梦人生
    2020-12-12 14:49

    Second case is also inefficient in terms of String pool, you have to explicitly call intern() on return reference to make it intern.

提交回复
热议问题