hi,
When the string is created using the String object constructed then string is created on the heap.But when the string is created using "",then the string is created in the pool.
So when you compare using the equals it always compare the contents of the string instead of comparing the string reference address.
Here is a small snippet to make you dance with the string objects on heap and strings created in the pool:
String s1= "dance";
String s2= new String("dance");
String s3= "dance";
here s1==s3 will always return true beacause both of them are created in the string pool and share the same reference address.
Suppose if you compare s1==s2. This will not return true as s1 is created in the pool and s2 is on the heap as object.So both of them does not share the same address.
But s1.equals(s2) will return true as equals compares the contents of both the variables.
Hope i made you dance with pool girl and heap girl???
please let me know if you still not clear about the explanation.
Thanks,
Somasekar.
