Hi all,
--------------------------------------------------
class
Test {
public static void main(
String args[]) {
String ab="AB"; // line1
String a = "A", b = "B", c = a+b, d = a+b;
System.out.print(((a+b)==(a+b)) + ",");
System.out.print((c==d) + ",");
System.out.print(c.equals(d));
}
}
----------------------------------------------------
The above program outputs result as "false,false,true".
on line1 we declare variable ab which will put "AB" string pool. So when we do a+b then it should return the same string reference "AB" as it is already in the string pool.
Based on above logic c==d should return true, but it returned false in the above code.
Pls explain with details.
Raju