In Java,
String s1 = new String("abc");
String s2 = new String("ab") + new String("cd");
Will string "abc" and "abcd" be created in string constant pool?
In Java,
String s1 = new String("abc");
String s2 = new String("ab") + new String("cd");
Will string "abc" and "abcd" be created in string constant pool?
Neither s1
nor s2
will point to strings in the constant pool because you created them by a combination of explicit constructor calls and concatenation. Only the string literals "abc", "ab", and "cd" will be in the constant pool.
You would need to explicitly intern()
the new instances. In that case, s1 == "abc"
would become true.