The output I got was : With == s3==s4 s7==s6 with equals s1.equals(s2) s3.equals(s4) s1.equals(s3) s7.equals(s6)

Here with equals, when it is comparing two string objects s1 and s2 it is returning true, and similarly it does compare StringBuffers,and gives true for s7 and s6. I know s6 and s7 point to the same reference. But why is it not comparing s5 and s6, similar to comparing s1 and s2 ? ie why is it not returning true? Please ,can someone generally explain the working of equals() and if it is used to compare the values in 2 objects, why can't it compare a String and StringBuffer. (the commented line gives a compiler error). If this has already been discussed anywhere else in this forum, please give me the links also. Thank you in advance Usha

1. Search for StringBuffer using the "Search" facility in this forum. 2. StringBuffer does not override the equals() method. So any combination involving a string buffer and equals method will retrun false. 3. new String(string) or new StringBuffer(string) will always create a new object. Thus the comparision using the reference variables will always be false.