I have below code, but I don't understand how the output is working.
String s1 = "hello";
String s2 = "hello";
String s3 = new String("hello");
String s4 = new String("hello");
System.out.println(s1==s2);
System.out.println(s3==s4);
The output is true then false. But the hashcode value for all s1,s2,s3 and s4 is same.
Then how one is returning true and another one is returning false. Could you please make me understand this.