- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is string constant pool in Java?
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.
And whenever we try to create another String as
String str2 = "Hello";
JVM verifies whether any String object with the same value exists in the String constant pool, if so, instead of creating a new object JVM assigns the reference of the existing object to the new variable.
And when we store String as
String str = new String("Hello");
using the new keyword, a new object with the given value is created irrespective of the contents of the String constant pool.
- Related Articles
- Why String literal is stored in String Constant Pool in Java?
- What are the differences between the Heap memory and the String Constant Pool in Java?\n
- How is the java memory pool divided?
- What is an object pool in C#?
- Java regex to exclude a specific String constant
- What is a constant and how to define constants in Java?
- What is a sub string in Java?
- What is Java String Class?
- What is Java String literal?
- What is Number.NEGATIVE_INFINITY constant in JavaScript?
- What is Proportionality constant ?
- What is Avogadro’s constant?
- What is special about string class in Java?
- What is the package for String Class in Java?
- What is the difference between String s1 = "Hello" and String s1= new String("Hello") in java?

Advertisements