public class Test2 {
public static void main(String[] args) {
String s1="Come back";
String s2="Come back";
String s3=s1;
if(s1==s2)
System.out.println("Equal");
else
System.out.println("Not Equal");
if(s1==s3)
System.out.println("Equal");
else
System.out.println("Not Equal");
}}
Output: equal equal
, I expected not equal equal
. My lecturer said that "==" statement compares references of variables.The references of s1 and s2 are different. Can anyone explain this?