Member-only story
STRING-INTERVIEW-QUESTIONS
What Does String Pool Mean in Java?
Know about the String Pool in Java and how objects are stored and retrieved from the String Pool.
What is String Pool in Java?
It is a Pool of Strings stored in the Heap Memory. All the strings created are stored in this pool if they do not already exist in the pool.
String class is immutable class and hence all string objects created using literals or new operators cannot be changed/modified.
String Objects Are Created in Two Ways:
1. Using double quotes(“ ”) [when String literals are used ]
String name1 = “Java”;The above statement creates a string object and places it in a string pool if it is not already present in the string pool and a reference is assigned to name1.
In this case, only one object is created.
2. Using the ‘new’ keyword :
String name2 = new String(“newJava”);The above statement creates a string object in heap memory and checks whether it is present in the string pool or not…









