Junior — Middle
Where in memory is an interned string stored in Java?
sobes.tech AI
Answer from AI
Interned strings in Java are stored in a special string pool. In modern JVM versions, this pool is located in the memory area called the Heap. Previously, before Java 7, the string pool was in PermGen (Permanent Generation), but starting from Java 7 and onwards, including Java 8 and above, the string pool was moved to the Heap.
This allows for more efficient memory management and garbage collection. When the String.intern() method is called, the string is added to the pool if it is not already there, and a reference to this string in the pool is returned.
Thus, interned strings are stored in the Heap in a dedicated area allocated for the string pool.