This prints true (even though we don't use equals method: correct way to compare strings)

    String s = "a" + "bc";
    String t = "ab" + "c";
    System.out.println(s == t);

When compiler optimizes your string literals, it sees that both s and t have same value and thus you need only one string object. It's safe because String is immutable in Java.
As result, both s and t point to the same object and some little memory saved.

Name 'string pool' comes from the idea that all already defined string are stored in some 'pool' and before creating new String object compiler checks if such string is already defined.

Answer from Nikita Rybak on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › string-constant-pool-in-java
String Constant Pool in Java - GeeksforGeeks
October 28, 2025 - The Java String Pool (also called the String Intern Pool) is a special memory area inside the heap that stores string literals.
🌐
Medium
medium.com › @AlexanderObregon › how-javas-string-pool-works-and-why-it-matters-306e2ea81147
How Java’s String Pool Works and Why It Matters | Medium
February 16, 2025 - Java’s string pool is designed to save memory by keeping string literals in a shared space. Instead of creating a new string every time, Java reuses existing ones when possible, which helps reduce memory usage and boost performance.
🌐
Baeldung
baeldung.com › home › java › java string › guide to java string pool
Guide to Java String Pool | Baeldung
August 20, 2025 - The String object is the most used class in the Java language. In this quick article, we’ll explore the Java String Pool — the special memory region where Strings are stored by the JVM.
🌐
Scaler
scaler.com › home › topics › java › string pool in java
String Pool in Java - Scaler Topics
February 27, 2022 - String pool is a storage space in the Java heap memory where string literals are stored. It is also known as String Constant Pool or String Intern Pool. It is privately maintained by the Java String class. By default, the String pool is empty.
🌐
Edureka
edureka.co › blog › java-string-pool
What is String Pool in Java | String Pool Examples | Edureka
June 6, 2023 - String Pool in Java is a pool of Strings stored in Java Heap Memory. This tutorial will help you with a detailed approach to Java String Pool with examples.
🌐
DigitalOcean
digitalocean.com › community › tutorials › what-is-java-string-pool
What is Java String Pool? | DigitalOcean
August 3, 2022 - String Pool is possible only because String is immutable in Java and its implementation of String interning concept. String pool is also example of Flyweight design pattern. String pool helps in saving a lot of space for Java Runtime although it takes more time to create the String.
🌐
CodeHS
codehs.com › tutorial › david › understand-the-java-string-pool
Tutorial: Understand the Java String Pool | CodeHS
In this tutorial, you will take a deeper dive into understanding how the String pool works and when Java uses the String pool versus creating a separate object.
Find elsewhere
🌐
Medium
muratakkan.medium.com › understanding-and-using-the-java-string-pool-in-java-d60d3176716
Understanding and Using the Java String Pool in Java - Murat
December 31, 2022 - Java String Pool is a special storage area in the Java heap where string literals are stored. It is implemented to improve the performance…
🌐
Medium
antony-s-smirnov.medium.com › java-string-pool-594f19b1bb58
Java String Pool.. A Java String pool refers to a… | by Anton Smirnov | Medium
February 25, 2024 - In essence, a String Pool is a collection of strings stored in a specifically designated area within the Heap. The String Pool exists thanks to the immutability of strings in Java and the implementation of string interning.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › string pool in java
String Pool in Java Explained with Examples
April 22, 2026 - The pool is a subset of the method area memory and uses less space than the heap. ... Explanation: Although a and b have the same content, they live in different parts of memory. ... Saves memory by reusing identical string literals.
🌐
LinkedIn
linkedin.com › pulse › java-strings-string-pool-muhammad-noman
Java Strings - String Pool
July 8, 2023 - String pool is a storage space in the Java heap memory where string literals are stored. It is also known as String Constant Pool or String Intern Pool. It is privately maintained by the Java String class. By default, the String pool is empty.
🌐
Study.com
study.com › business courses › business 104: information systems and computer applications
Java String Constant Pool: Concept & Mechanism - Lesson | Study.com
October 12, 2018 - He is an adjunct professor of computer science and computer programming. ... The Java strings constant pool is the sum total available memory for Java to use declaring active strings.
🌐
Java String
javastring.net › home › java string pool
Java String Pool
July 1, 2019 - Java String Pool is the special area in the heap memory to store string objects. There are two ways to create string objects. If we use double quotes to create a string object, it’s stored in the string pool.
🌐
Delft Stack
delftstack.com › home › howto › java › string pool java
String Pool in Java | Delft Stack
March 13, 2025 - The String Pool, also known as the String Intern Pool, is a special storage area in the Java heap where Java stores string literals. This mechanism helps in reusing string objects, thereby saving memory and improving performance.
🌐
Medium
medium.com › @bhangalekunal2631996 › understanding-java-string-constant-pool-concepts-mechanisms-and-examples-with-diagrams-010122c7ced0
Understanding Java String Constant Pool: Concepts, Mechanisms, and Examples with Diagrams | by Kunal Bhangale | Medium
January 5, 2025 - In this article, we’ll explore ... diagrams. The String Constant Pool (SCP) is a dedicated memory region in the Heap where the Java Virtual Machine (JVM) stores string literals....
Top answer
1 of 5
166

The string pool is the JVM's particular implementation of the concept of string interning:

In computer science, string interning is a method of storing only one copy of each distinct string value, which must be immutable. Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned. The distinct values are stored in a string intern pool.

Basically, a string intern pool allows a runtime to save memory by preserving immutable strings in a pool so that areas of the application can reuse instances of common strings instead of creating multiple instances of it.

As an interesting side note, string interning is an example of the flyweight design pattern:

Flyweight is a software design pattern. A flyweight is an object that minimizes memory use by sharing as much data as possible with other similar objects; it is a way to use objects in large numbers when a simple repeated representation would use an unacceptable amount of memory.

2 of 5
61

The string pool allows string constants to be reused, which is possible because strings in Java are immutable. If you repeat the same string constant all over the place in your Java code, you can actually have only one copy of that string in your system, which is one of the advantages of this mechanism.

When you use String s = "string constant"; you get the copy that is in the string pool. However, when you do String s = new String("string constant"); you force a copy to be allocated.

🌐
Medium
medium.com › @liberatoreanita › lets-discover-and-analyze-string-pool-in-java-7fcb2f8ba748
Let’s discover and analyze String Pool in Java | by Anita Liberatore | Medium
May 6, 2024 - If the string is already present in the pool, a reference to the existing instance is returned. However, if the string is not found in the pool, a new String object is instantiated and added to the pool. Now, let’s move beyond the theory and delve into the practical workings of the String pool in Java.
🌐
Medium
medium.com › @kamran.babayevv › string-pool-in-java-d505753a494d
String Pool in Java. In Java, String is the most important… | by Kamran Babayev | Medium
July 6, 2023 - String pool is nothing but a storage area in Java heap where string literals stores. It is also known as String Intern Pool or String Constant Pool. It is just like object allocation.
🌐
Javatpoint
javatpoint.com › string-pool-in-java
String Pool in Java - Javatpoint
March 17, 2014 - Java Program to divide a string in 'N' equal parts.