A string can be initialised in two ways :
String s="ABCD";
OR
String s=new String("ABCD");
Are these two same or different ??
Again I have noticed that
String s="ABCD";
String z="ABCD";
boolean b=s.equals(z);
results in true but
String s=new String("ABCD");
String z=new String("ABCD");
boolean b=s.equals(z);
results in false.
Can anyone please explain me why this happens??
refer to the same Strings in memory pool.
Howewver
produce separate memory spaces for the Strings.
So the output is such.
This also answers your first question.