Possible duplicate:
Creating a String Object Using the New and Comparing It with the intern Method
I played with the Strings to understand them more, and I noticed something that I can not explain:
String str1 = "whatever"; String str2 = str1; String str3 = "whatever"; System.out.println(str1==str2);
How does the last line give the truth? this means that both str1 and str3 have the same memory address.
Is this a compiler optimization that was smart enough to detect that both string literals are the same ("independently") and thus assign str1 and str3 to the same object? Or am I missing something in the basic row mechanics?
java string javac
MohamedEzz
source share