String Heap and Intern Pool

Dear Sr,
Why is string kept in Intern pool in heap in java.

Hi Mohit
We know that String is one of the most used classes in Java. Since the strings are immutable, the JVM can optimise the amount of memory allocated to it by storing only one copy of each literal String in the pool. If we place the string outside of intern pool, say in PermGem space, which has fixed space, it can’t be expanded at run time and thus we can get OutOfMemory error.
Hope this helps.

Hi Mohit, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.