As clear from here, the actual characters that comprise a String in Java are actually stored in the private final char value[]; character array.
Can someone please help me in understanding the following questions for an expression String text = "Hello World";
- What is actually stored in StringPool ? I've read many places that its the
Stringliteral. If thats the case, what exactly is the difference between a String Object and a String literal as both must be backed by achar[] - If the String reference is marked as Constant (final), will it be stored in the
Runtime Constant Poolinside theMethod Areaas well ? - As mentioned here, the actual
char[] valueis created on the heap only. So whenintern()method is called on aStringobject created usingnewoperator, what will be copied to the StringPool (assuming its not the character array) ?
Edit :
As mentioned here, StringPool is implemented as a HashMap. So what could be the key and value for the same ? It appears that the value cannot be the char[] value as the same is created on the Heap.

