When do (not) two strings with same content share the same memory?

柔情痞子 提交于 2019-12-01 21:30:25

@gennady-vanin-novosibirsk....

String s1="Java";String s2="Java";String s3="Java";String s4="Java";

  1. The above all objects available in StringConstantPool location those are all objects are pointing to only one ("Java") location
d'alar'cop
Is string pool created per class basis or per JVM basis?

There is one String pool per JVM ... unless you are using some exotic JVM where they've decided to implement it differently.

I think that answers it, right?

from similar question

Waji

Same memory location:

String s1="Hola";
String s2="Hola";

Distinct memory location:

String s1="Hola";
String s2=new String("Hola"); 

Strings of same contents will share same space for every instance of same JVM

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!