How is the following returning 'false'?
String a = "123";
a = a + "456";
String b = "123456";
System.out.println((a == b));
From what I understand,
- String "123" is created in string pool and assigned to 'a'
- String "456" created in pool and further "123456" created in the pool and 'a' starts referencing it.
- When 'b' is created for the value "123456"; JVM would discover an existing String "123456" in String pool and 'b' will also refer it.
Hence it should return true!
Where am I going wrong?