When you use the new key word you are creating a new String object here for s1. Then for s2 you are referring to a second object. s3 simply latches onto the same object s2 is referring to because of string pooling. Therefore s1==s2 will be false because they are two different objects. s1.equals(s2) or s1.equals(s3) will return true because now you are comparing the contents of the objects.
Joined: Aug 16, 2005
HI Kavin Kumar according to ur code.
whenver u create a string with new key word.it will be given a memory address. if u create a string using just String s1= "abc"; then this string will be in a pool. if u create another string with same contents ,but without new keyword then that string will go the already existing string pool.(where "abc "is there);
So , s1==s3 gives "NOT GOOD":// references are not same. s3==s4 gives "EQ".references are same.
s1.equals(s3) gives "Good".// character by character is exactly the same.
According to ur code
Joined: Aug 06, 2005
Hai == USED TO COMPARE REFERENCE VARIABLES REFEREING TO SAME TO CLASS OR NOT .equals() USED TO COMPARE THE CONTENT OF THE OBJECTS