Why doesn't it give the output arit amit true true
Because it's giving false does it mean s2 is not refering to the string already in the String constant pool called "arit". Why does it create a new object when String "arit" already exists.
The line String s2=s1.replace('m','r'), this actually creates a new object in the heap.It means that s2 now is pointing on a different object.When you are going to use the == for comparison it will compare both operands via their reference type. It is another story if you are going to use the equal operator(s2.equals(s3) which will turn out true.Both operands are compared by their value.