ProLesson 3.2Beginner2 min readUpdated 30 October 2026
The string pool, == and equals
Where Java keeps string literals, why == sometimes works and sometimes doesn't, and what intern() does. A classic interview topic.
This is one of the most asked Java interview questions, and it's easy once you can picture it. Java keeps a special area of memory for string literals, called the string pool.
01Picture the pool
When you write a literal like "java", Java looks in the pool first. If "java" is already there, it reuses that object. If not, it adds it. new String("java") skips the pool and always creates a separate object on the heap.
text
String a = "java"; → pool: ["java"] ← a
String b = "java"; → reuses it ← b (a and b are the same object)
String c = new String("java"); → new heap object ← c (different object, same text)Loading the rest of the lesson…