Anyone to throw right on the code and its output ?
public class HelloWorld { public static void main(String[] args) { String s1 = "Hello World"; String s6 = "Hello" + " World"; String s7 = "Hello"; String s8 = " World"; String s9 = s7 + s8; String s10 = s7 + " World"; System.out.println(s1==s6); System.out.println(s1==s9); System.out.println(s1==s10); System.out.println(s9==s10); } } Output :
true false false false I understand that s1 is created in the string constant pool. I am wondering how the creation of s6, s9 and s10 due to the use of the concatenation operator.
==?s1ands6are compile-time constants (which is actually the same"Hello World"that belongs to the classHelloWorld), but others aren't (although they are added to the literal pool after creation at runtime).