I have this code,
class Test{
public static void main(String args[])
{
Boolean a;
Boolean b;
char [] c={'S','t','r','i','n','g'};
a=("String".replace('g','G')=="String".replace('g', 'G'));
b=("String".replace('g','g')=="String".replace('g', 'g'));
System.out.println("---"+a);
System.out.println("---"+b);
System.out.println(c.toString()=="String");
}
The Out put is ---false ---true false
I did visit JLS documentation by oracle where it says. The replace method: Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. If the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned. Otherwise, a new String object is created that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar.
when the O/p one is false why the O/p second is true?
JLS document says about toString method: This object (which is already a string!) is itself returned. then why not O/p third is true?
Can any one please explain it to me
Thanks in advance GPAR