JavaIntermediate#strings

What is the String pool (intern pool)?

A special memory area in the heap where the JVM stores unique String literals for reuse, avoiding duplicate objects. Strings created via new bypass the pool unless intern() is called explicitly.

Example
String a = "hello";      // goes into pool
String b = "hello";      // reuses pooled reference
String c = new String("hello").intern(); // forces c into pool
a == b; // true
a == c; // true

Related Questions

1
JavaBeginner#strings

How do you reverse a String in Java?

Open
2
JavaBeginner#strings

How do you check if a String is a palindrome?

Open
3
JavaBeginner#strings

What is the difference between String.format and concatenation?

Open