For Objects,Strings == compares references.Not value When we do ,String s2=s1.replace('m','r'); it returns a new String string..given to s2. String s3="arit"; one more string given to s3. both strings have same value ,but == sees references.which are different.
Correct me if I am wrong here, but doesn't this basically deal with where the object is located in memory?
From the book.....when you call String s = new String("amit"); A new string object is placed in heap memory. But when you call String t = "amit", there is no object contained on the heap, instead, you are creating a String literal contained in the String Pool Memory. So as someone previously said, when you use == you are comparing the references, since the references are each pointing to two different sets of memory which don't know about each other the answer is false.
Isn't this this real reason it returns false or am I off?