In the below code, by hashCode()
it seems 2 objects got created. Then although s1 == s3
is giving true, but why s1 == s4
is giving false ?
public class Main {
public static void main(String[] args) {
String s1 = new String("jordi") ;
String s2 = s1.toUpperCase() ;
String s3 = s1.toLowerCase() ;
String s4 = new String("jordi") ;
System.out.println(s1.hashCode());
System.out.println(s2.hashCode());
System.out.println(s3.hashCode());
System.out.println(s4.hashCode());
System.out.println(s1==s2);
System.out.println(s1==s3);
System.out.println(s1==s4);
}
}
This gives output as :
101312786
70775026
101312786
101312786
false
true
false