What is the String pool in Java?

The String Pool is a special area in the Java Heap Memory where the JVM stores string literals. Its primary purpose is to optimize memory usage by reusing existing String objects instead of creating duplicate objects with the same value.

Key Points

Example

If multiple variables contain the string literal "Java", the JVM stores only one copy in the String Pool and all variables reference the same object.

public class Demo {

    public static void main(String[] args) {

        String str1 = "Java";
        String str2 = "Java";
        System.out.println(str1 == str2); // true

        String str3 = new String("Java");
        System.out.println(str1 == str3); // false

        System.out.println(str1.equals(str3)); // true
    }
}

Memory Representation

String str1 = "Java";
String str2 = "Java";

Interview Tip

A concise interview answer is

The String Pool is a special memory area inside the heap where Java stores string literals. Before creating a new string literal, the JVM checks the pool and reuses an existing object if the same value already exists. This improves memory efficiency and application performance.

Last updated: 11 November 2026

Previous question: Discuss the difference between finalize() and finally. Under what circumstances might finalize() not get called in a Java application?

Next question: Are there any scenarios where using the string pool might not be beneficial?

More Core Java - Level II interview questions

All Core Java - Level II questions