Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Interview question

What is String Pool (String Constant Pool) in Java? Java में String Pool (String Constant Pool) क्या है?

Answer

String Pool is a special memory region where String literals are stored. Java checks if a String already exists in the pool before creating a new one.

String s1 = "Hello";
String s2 = "Hello";
String s3 = new String("Hello");
System.out.println(s1 == s2);  // true
System.out.println(s1 == s3);  // false
String s4 = s3.intern();
System.out.println(s1 == s4);  // true

String Pool एक special memory region है जहाँ String literals store होते हैं।

Was this answer clear?