🌐
TutorialsPoint
tutorialspoint.com › What-is-string-constant-pool-in-Java
What is string constant pool in Java?
July 30, 2019 - When you store a String as String str1 = "Hello"; directly, then JVM creates a String object with the given value in a separate block of memory known as String constant pool.
🌐
GeeksforGeeks
geeksforgeeks.org › java › string-constant-pool-in-java
String Constant Pool in Java - GeeksforGeeks
October 28, 2025 - When a string is declared in Java, two separate memory areas are involved: Stack: Stores the variable reference. Heap (String Constant Pool): Stores the actual string object value.
🌐
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.
🌐
Medium
rameshfadatare.medium.com › what-is-string-constant-pool-in-java-explained-with-examples-78c6477519a8
What is String Constant Pool in Java? | Explained with Examples | by Ramesh Fadatare | Medium
March 25, 2025 - This is because of something called the String Constant Pool. ... In Java, the String Constant Pool (also called the String Intern Pool) is a special memory area in the Java Heap that stores string literals.
🌐
Javatpoint
javatpoint.com › string-pool-in-java
String Pool in Java - Javatpoint
March 17, 2014 - Java program to find the percentage of uppercase, lowercase, digits and special characters in a string
🌐
Baeldung
baeldung.com › home › java › java string › where does java’s string constant pool live, the heap or the stack?
Where Does Java’s String Constant Pool Live, the Heap or the Stack? | Baeldung
May 29, 2025 - The String constant pool is a special memory area. When we declare a String literal, the JVM creates the object in the pool and stores its reference on the stack. Before creating each String object in memory, the JVM performs some steps to decrease ...
🌐
How to do in Java
howtodoinjava.com › home › string › java string constant pool
Java String Constant Pool
January 9, 2023 - We know that string literals are created in the String pool, and string objects are created in the heap memory area. We can use the method String.intern() to create string literals for the string objects. When invoked on a string object, method intern() creates an exact copy of a String object in the heap memory and stores it in the String constant pool.
🌐
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.
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java string › guide to java string pool
Guide to Java String Pool | Baeldung
August 20, 2025 - We can manually intern a String in the Java String Pool by calling the intern() method on the object we want to intern. Manually interning the String will store its reference in the pool, and the JVM will return this reference when needed.
🌐
Decodejava
decodejava.com › java-string-constant-pool.htm
Java String Constant Pool- Decodejava.com
String s1 = "Hello"; // Statement 1 String s2 = "Hello"; // Statement 2 String s3 = new String("Hello"); // Statement 3 After executing these three statements, String constant pool part on heap(a special area on the heap) and the other normal part of heap are represented by Figure 1. After executing statement 1, String object with value Hello is stored in String Constant Pool part on the heap because this object is constructed without using the new keyword.
🌐
Edureka
edureka.co › blog › java-string-pool
What is String Pool in Java | String Pool Examples | Edureka
June 6, 2023 - A reference for the literal “Apple” is then placed in the string constant pool memory.
Top answer
1 of 5
33

Maybe this will aid your understanding:

String literal = "test";
String one = new String(literal);
String two = "test";

System.out.println(literal == two); //true
System.out.println(one == two); //false

In the example you posted:

String one = new String("test");
String two = "test";

the reference passed to the constructor String(String) has the same value as the reference two due to interning. However, the string itself (referenced by these two references) is used to construct a new object which is assigned to reference one.

In this example, there are exactly two Strings created with the value "test": the one maintained in the constant pool and referenced whenever you use the literal "test" in an expression, and the second one created by the "new" operator and assigned to the reference one.

Edit

Perhaps you're confused about this statement:

When the compiler encounters a String literal, it checks the pool to see if an identical String already exists.

Note that this might be more clearly stated as:

When the compiler encounters a String literal, it checks to see if an identical String already exists in the pool.

Strings are only put in the pool when they are interned explicitly or by the class's use of a literal. So if you have, for example, this scenario:

String te = "te";
String st = "st";

String test = new String(te) + new String(st);

then while a String will exist with the value test, said String will not exist in the pool as the literal "test" has never occurred.

2 of 5
8
    //Creates a new object even if one exists in the pool
    String s1 = new String("Tendulkar");

    // makes a new object string and then the reference is available to the pool
    String s2 = s1.intern();

    //this object is not created but references the address present in the pool
    String s3 = "Tendulkar";

    System.out.print(s1==s2); // results in false
    System.out.print(s2==s3); //very very true !!!
🌐
Java Knowledge Base
javaknowledgebase.com › home › java tutorial › string constant pool
Java String Contant Pool– Interning, Immutability & Examples
September 8, 2025 - When we create a String using the new() operator, a new object is always created in heap memory. But when we use a String literal like "Java Knowledge Base", the JVM checks the String Pool first — if the string already exists, it reuses it; otherwise, it adds the new string to the pool for future use.
🌐
DEV Community
dev.to › codegreen › explain-string-constant-pool-in-java-2b0o
Explain String Constant Pool in Java - DEV Community
November 27, 2024 - The String Constant Pool is an efficient way to manage String literals in Java, allowing reuse of String objects and saving memory. However, using the new keyword bypasses this optimization, leading to the creation of new String objects even ...
🌐
JavaMadeSoEasy
javamadesoeasy.com › 2016 › 10 › difference-between-constant-pool-and.html
JavaMadeSoEasy.com (JMSE): Difference between constant pool and String pool in java
The constant pool table is indexed from 1 to constant_pool_count - 1. ... String intern pool. What is the String Pool in java?
🌐
Medium
medium.com › @kalanasudeshgunaweera › string-pool-in-java-683810651b6e
“String Pool” in Java…
September 14, 2023 - In this article, I’ll explore what the String Pool is, how it works, and why it matters for memory optimization in your Java programs.String pool is the specific memory area in the java heap memory where the JVM store the String objects.
🌐
Javainsimpleway
javainsimpleway.com › string-constant-pool
String constant pool | Javainsimpleway
Each time we create a new String literal , JVM first looks at the String constant pool, if the same String literal already exist in pool, reference to the same pooled instance will be returned rather than creating a new string object. If string literal does not exist in the pool then new string ...