"java" doesn't get destroyed; it's just not referenced anymore. For most objects, that means the garbage collector will eventually delete it. For this particular String, since it's a literal (a String constant that appears in the source code) it's held in the string pool, so it won't be GCd.
Hi friends, can anybody tell me why st1 == st4 is false and st1 == str5 is false.
Thank you all in advance. Have a nice day.
There is no rule that we all should know everything. Lets learn few things of everything here.
Ankur Jain Kothari
Joined: Feb 08, 2010
String s4 is a new object...so calling == gives false as they are different objects...since s5 is "change me" + words....this creates a new string in the pool...so s1 and s5 refers to different objects in the string pool...s5 is not a constant because of this
Do What You Wanna Be....Taking Things The Way They Come
scjp 1.6 91 percent, scmad 90 percent(rounded off to nearest integer)
Joined: Mar 16, 2010
Hi Ted can you be more specific, really I haven't understood.
As you said str1 and str4 are different objects, I got a false. Then str1 and str2 are also different objects, but they are returning true. Why?