Hello,
can any body explain me why the output of this coming out only "same values"...
because what i read is that JVM creats a pool memory for x1 ,x2 and for "c"...
After concatenation the resulting value of x2 is same as that of reference x1 i.e "abc"
so why the comparision is giving false result....
public class Simple {
public static void main(
String[] args) {
String x1 = "abc";
String x2 = "ab";
x2=x2+"c";
System.out.println(x2);
if ( x1 == x2 )
{ // comparing reference vars
System.out.println("reference comparision");
}
if ( x1.equals(x2) ) { // comparing values
System.out.println("same values");
}
}
}
Regards
Hrushikesh