public class StrEqual {
public static void main(String[] args) {
String s1 = "hi";
String s2 = new String("hi");
System.out.println(s1);
System.out.println(s2);
if(s1 == s2){
System.out.println("s1 and s2 are equal");
}
else{
System.out.println("s1 and s2 are not equal");
}
}
}
In the above code s1 and s2 both referring to the string "hi". But why the output of the program is- 's1 and s2 are not equal' ? Thank you