You are here: Home / Topics / What is Java String Pool?

What is Java String Pool?

Filed under: Java Interview Questions on 2024-10-25 14:29:27

A Java String Pool is a place in heap memory where all the strings defined in the program are stored. A separate place in a stack is there where the variable storing the string is stored. Whenever we create a new string object, JVM checks for the presence of the object in the String pool, If String is available in the pool, the same object reference is shared with the variable, else a new object is created.

Example:

String str1="Hello";
// "Hello" will be stored in String Pool
// str1 will be stored in stack memory

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.