Friday, June 14, 2013

What is a string pool?

JVM has the String Pool. All the String Objects which are created by assignment are stored in the pool. This pool is present in the heap. So whenever any assignment is done for a String, the JVM first checks in the String Pool whether that String is already present or not. This is done by calling intern() method present in the String class. If the JVM finds the same String then it return the same reference else it creates a new one.

But, if you use the new Operator, a new object is created every time.