class strtest1
{
public static void main(
String args[])
{
String s=new String("raja");
if(s=="raja")
{
System.out.println("1 is true");
}
if("raja"=="raja")
{
System.out.println("2 is true");
}
}
}
when u run the above code, result obtained is "2 is true".
when u create the string using String s="raja", the result is
"1 is true"
" 2 is true"
please explain how.
i have another doubt.how does == operator work when comparing
"raja"=="raja"
== compares only the references.how does this work?
how many string objects are created at the end of this code