The answer is technically neither. According to the Java Virtual Machine Specification, the area for storing string literals is in the runtime constant pool. The runtime constant pool memory area is allocated on a per-class or per-interface basis, so it's not tied to any object instances at all. The runtime constant pool is a subset of the method area which "stores per-class structures such as the runtime constant pool, field and method data, and the code for methods and constructors, including the special methods used in class and instance initialization and interface type initialization". The VM spec says that although the method area is logically part of the heap, it doesn't dictate that memory allocated in the method area be subject to garbage collection or other behaviors that would be associated with normal data structures allocated to the heap.

Answer from Duane Moore on Stack Overflow
🌐
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.
🌐
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 - It includes local primitive variables, references of heap objects, and methods in execution. Heap allows dynamic memory allocation, stores the Java objects and JRE classes at the runtime.
Top answer
1 of 7
81

The answer is technically neither. According to the Java Virtual Machine Specification, the area for storing string literals is in the runtime constant pool. The runtime constant pool memory area is allocated on a per-class or per-interface basis, so it's not tied to any object instances at all. The runtime constant pool is a subset of the method area which "stores per-class structures such as the runtime constant pool, field and method data, and the code for methods and constructors, including the special methods used in class and instance initialization and interface type initialization". The VM spec says that although the method area is logically part of the heap, it doesn't dictate that memory allocated in the method area be subject to garbage collection or other behaviors that would be associated with normal data structures allocated to the heap.

2 of 7
61

As explained by this answer, the exact location of the string pool is not specified and can vary from one JVM implementation to another.

It is interesting to note that until Java 7, the pool was in the permgen space of the heap on hotspot JVM but it has been moved to the main part of the heap since Java 7:

Area: HotSpot
Synopsis: In JDK 7, interned strings are no longer allocated in the permanent generation of the Java heap, but are instead allocated in the main part of the Java heap (known as the young and old generations), along with the other objects created by the application. This change will result in more data residing in the main Java heap, and less data in the permanent generation, and thus may require heap sizes to be adjusted. Most applications will see only relatively small differences in heap usage due to this change, but larger applications that load many classes or make heavy use of the String.intern() method will see more significant differences. RFE: 6962931

And in Java 8 Hotspot, Permanent Generation has been completely removed.

🌐
TutorialsPoint
tutorialspoint.com › article › what-are-the-differences-between-the-heap-memory-and-the-string-constant-pool-in-java
What are the differences between the Heap memory and the String Constant Pool in Java?
The above Java program will produce the following output: ... Within the heap, the String constant pool is located. It stores unique string literals. Whenever a new string variable is created, the JVM will match the specified value with the ...
🌐
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 - The Java string constant pool is an area in heap memory where Java stores literal string values. The heap is an area of memory used for run-time operations. When a new variable is created and given a value, Java checks to see if that exact value ...
🌐
Medium
abhijit-pal.medium.com › understanding-string-objects-heap-and-string-constant-pool-b233bbfdce5a
Understanding String Objects, Heap, and String Constant Pool | by Abhijit | Medium
May 1, 2024 - In the above example, two separate ... String Literal and String Constant Pool Java uses a special area of the heap memory called the string constant pool to store string literals....
🌐
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...
Find elsewhere
🌐
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.
🌐
CodingTechRoom
codingtechroom.com › tutorial › java-understanding-java-string-constant-pool-heap-vs-stack
Understanding Java String Constant Pool, Heap, and Stack - CodingTechRoom
The garbage collector manages memory in the heap, reclaiming memory used by objects that are no longer referenced. ... Solution: String intern method can be used to pool strings by storing them in the constant pool.
🌐
javathinking
javathinking.com › blog › where-does-java-s-string-constant-pool-live-the-heap-or-the-stack
Where Does Java's String Constant Pool Live? Heap vs Stack Explained — javathinking.com
Stores primitives and references: ... objects in the Heap) live here. The String Constant Pool (SCP) is a specialized memory area in Java designed to optimize memory usage for String literals....
🌐
CodingTechRoom
codingtechroom.com › question › java-string-constant-pool-heap-or-stack
Where Is Java's String Constant Pool Located—Heap or Stack? - CodingTechRoom
In Java, the String constant pool, also known as the String pool, is a special area of memory that stores String literals. This pool is part of the heap memory managed by the Java Virtual Machine (JVM), rather than the stack.
🌐
Smartprogramming
smartprogramming.in › tutorials › java › string-constant-pool
String Constant Pool in Java - Memory Management Explained
So, let's understand what String Constant Pool is, how it works, and how String achieves memory management in Java. String Constant Pool (also known as String Literal Pool) is a special memory region inside the Heap area where Java stores string literals for memory efficiency and reusability.
🌐
Java Training School
javatrainingschool.com › home › string constant pool vs heap
String Constant Pool vs HEAP - Java Training School
March 26, 2023 - String Constant Pool is an area of the Heap that contains String objects created as literals (String s1 = "Arjun Kumar"). Important Points about String Constant Pool String Constant Pool is the part of HEAP area only String objects created as ...
🌐
Medium
medium.com › @meetroshni95 › understanding-string-constant-pool-and-heap-behavior-in-java-87c20f15e3f0
Understanding String Constant Pool and Heap Behavior in Java | by Roshni | Medium
January 8, 2025 - A special area in memory (part of the method area) where string literals are stored. If a string with the same content already exists in the pool, it is reused. ... Dynamically created string objects (using new String(), concat(), or + operator) ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › what-is-java-string-pool
What is Java String Pool? | DigitalOcean
August 3, 2022 - As the name suggests, String Pool in java is a pool of Strings stored in Java Heap Memory.
🌐
DEV Community
dev.to › tishaag098 › string-constant-pool-storage-of-strings-1784
String Constant Pool (Storage of Strings) - DEV Community
February 14, 2022 - A string constant pool is a separate place in the heap memory where the values of all the strings... Tagged with java, beginners, tutorial, programming.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › string pool in java
String Pool in Java Explained with Examples
April 22, 2026 - Since Java 7, it resides in the main heap memory, allowing better flexibility and fewer memory overflow issues. No, the String Pool is a unique feature for the String class because strings are immutable.
🌐
Medium
medium.com › @bitTobit › string-pool-heap-memory-dd429a867d50
String Pool & Heap Memory. Details about == operator and .equals()… | by Mayesha Mariza | Medium
July 24, 2025 - Therefore, “Topshe” is not a primitive type like int or char, but a reference type that points to an object in memory. The String Pool (also known as String Constant Pool) is a special area in Heap where Java stores string literals.