In below code HashCode of s1 and s3 are equal but s1==s3 returns false why?.Please clarify it. Here s1 ,s2 and s3 contains same content and HashCode . When run below code then out is
108274800
108274800
108274800
s1==s2
s1.equals(s2)
s1.equals(s3)
Code is given as follows...
public class StringTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s1="rahul";
String s2="rahul";
String s3=new String("rahul");
System.out.println(s1.hashCode());
System.out.println(s2.hashCode());
System.out.println(s3.hashCode());
if(s1==s2){
System.out.println("s1==s2");
}
if(s1==s3){
System.out.println("s1==s3");
}
if(s1.equals(s2)){
System.out.println("s1.equals(s2)");
}
if(s1.equals(s3)){
System.out.println("s1.equals(s3)");
}
}
}