String Pool是什么意思?以下声明之间有什么区别:
String s = "hello";
String s = new String("hello");
Run Code Online (Sandbox Code Playgroud)
JVM存储这两个字符串有什么区别吗?
如果我使用String.intern()来提高性能,因为我可以使用"=="来比较实习字符串,我会遇到垃圾收集问题吗?实习字符串的垃圾收集机制与普通字符串有何不同?
有没有办法在我们自己的程序中访问String常量池的内容?
假设我有一些基本代码可以做到这一点:
String str1 = "foo";
String str2 = "bar";
Run Code Online (Sandbox Code Playgroud)
现在我们的String常量池中有两个字符串浮动.有没有办法访问池并打印出上述值或获取池中当前包含的当前元素总数?
即
StringConstantPool pool = new StringConstantPool();
System.out.println(pool.getSize()); // etc
Run Code Online (Sandbox Code Playgroud)