Before we move on: I understand we should use .equals() to compare content. I am now just talking about if the actual references are the same for the following scenario...
Say we have the following:
String str1 = "str";
String str2 = "string";
String str3 = "ing";
String str4 = str1 + str3;
str1 = str4;
String str5 = "string";
System.out.println(str1==str2);//false
I think it supposed to be true since in the String pool, the reference to "string" should be the same, as str1 and str2, now are both "string". It should be true, but ends up as false.
System.out.println(str1.intern()==str2.intern());//true
I tried this, and it returned a true this time. Then I tried:
System.out.println(str1==str5);//false
System.out.println(str2==str5);//true
Also System.out.println("str"+"ing"=="string");//true
Aren't the supposed to come from the String pool? Could someone help explain this a bit?