Sorry beforehand for a basic question but can someone please explain me why:
String s = "lo";
String str7 = "Hel" + s;
String str8 = "He" + "llo";
System.out.println("str7 == str8 is " + (str7 == str8));
outputs false. I thought that str7 and str8 both point to the same object in String pool specifically because Strings are immutable.
Am I wrong? Are str7 and str8 are both not in the pool but in the heap? Why?
Can you please provide me with example of some String manipulation when the result would be indeed the same immutable string from the string pool?
PS:
String str9 = "He" +"llo";
System.out.println("str8 == str9 is " + (str9 == str8));
outputs true