我已经研究 Java 字符串有一段时间了
Java 字符串是特殊的
Java 中字符串的不变性
不变性:
现在,根据不可变性,String 类已经被设计成可以在其他地方/变量中重用 公共泳池中的值。如果将 String
创建为
String a = "Hello World!";
但是,如果我创建 String like
String b = new String("Hello World!");
why is this immutable as well? (or is it?). Since this has a dedicated heap memory, I should be able to modify this without affecting any other variable. So by design, was there any other reason why String
as a whole is considered immutable? Or is my above assumption wrong?
我想问的第二件事是关于 普通字符串池普通字符串池的
String c = "";
是否在池中创建了一个空项?
是否有任何帖子已经在这些? 如果有,可以有人分享的链接?