When a String is created using the keyword new it creates a new String object using a constructor that takes a String literal.
Does the literal get stored in the constant pool before the String constructor is called?
String hello = new String("Hello");
String literal = "Hello"; //Does "Hello" already exist in the pool
//or is it inserted at this line?
EDIT
In "OCA Java SE 7 Programmer I Certification Guide", Mala Gupta writes:
public static void main(String[] args)
{
String summer = new String("Summer"); // The code creates a new String object with the value "Summer". This object is not placed in the String constant pool.
String summer2 = "Summer" // The code creates a new String object with the value "Summer" and places it in the String constant pool.
}
She says on the first line that the String object that is created by new is not stored in the constant pool. This is fine, but what is not clear is if the literal "Summer" that goes in the constructor on the first line is. On the second line she says that the assignment of "Summer" to summer2 stores it in the constant pool, which implies that the literal on the first line was not interned.