☕ Java Beginner

What is the String pool in Java?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Java basics — a prerequisite for any developer role.

Answer

The String pool (or String constant pool) is a special memory area in the Java heap where String literals are stored and reused. When you create a String literal like String s = "hello";, the JVM first checks if "hello" already exists in the pool. If it does, it returns a reference to that existing object instead of creating a new one — saving memory. Two literals with the same value will point to the same object in the pool: String a = "hello"; String b = "hello"; a == b; // true. Strings created with new String("hello") always create a new object outside the pool. Use intern() to manually add a String to the pool.

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.