How String concatenation works in java?. This question is not for comparing Strings. Its for comparing objects and while concatenation i am getting only false. Why this is happen? I have written a code for comparing the String references
public class StringClass {
public static void main(String[] args) {
String s1 = new String("hello");
String s2 = new String("hello");
String s3 = "hello";
String s4 = "hello";
String s5 = "java";
String s6 = "developer";
String s7 = s5 + s6;
String s8 = "java" + s6;
String s9 = "javadeveloper";
String s10 = "java" + "developer";
System.out.println("s1 == s2 " + s1==s2);
System.out.println("s3 == s4 " + s3 == s4);
System.out.println("s7 == s9" + s7 == s9);
System.out.println("s9 == s10" + s9==s10);
}
}
In console i am getting like this
false
false
false
false
Why concatenation doesnt work in this code?. I am expecting the output like this
s1 == s2 false
s3 == s4 true
s7 = s9 false
s9 == s10 true