Why the following java code gives answer as:
not equal
equal.
Code:
String a=new String("abc");
String b=new String("abc");
String c="abc";
String d="abc";
if(a==b){
System.out.println("equal");
}else{
System.out.println("not equal");
}
if(c==d){
System.out.println("equal");
}else{
System.out.println("not equal");
}
I am confused as to what is the way the two statements
String a=new String("abc");
String c="abc";
differ in ?
In simple words what is the difference between the two assignments ?
Any help will be appreciated.
Thanks