String str = "Hello";
str = "Hello";
Above statements will create two objects on heap or same object will be return by jvm? Thanks in advance
String str = "Hello";
str = "Hello";
Above statements will create two objects on heap or same object will be return by jvm? Thanks in advance
String str = "Hello" it will go to SCP memory. like str pointing to your String variable"hello". there is only one object.
String literals are stored in the SpringPool.
In your above example, "Hello" is a string pool and there will be only one reference of this object in the string pool. Hence there will be only one object in the memory.