String Pool is basically used to cut down the number of String objects from the JVM. Suppose if the string is already exists in the pool, then a reference to the pooled instance returns. Java programming language make this type of optimization and since strings are immutable & can be shared without fear of data corruption. Each time your code create a string literal, the JVM checks the string literal pool first.If the string does not exist in the pool, a new String object instantiates, then is placed in the pool.
A JVM(Java Virtual Machine) comprises a string pool in which it keeps at most one object of any String. String literals always refer to an object in the string pool.Each string literal is a reference to an instance of class String.String objects created with the new operator do not refer to objects in the string pool but can be made to using String's intern() method. The java.lang.String.intern() returns an interned String, that is, one that has an entry in the global String pool. If the String is not already in the global String pool, then it will be added.
A JVM(Java Virtual Machine) comprises a string pool in which it keeps at most one object of any String. String literals always refer to an object in the string pool.Each string literal is a reference to an instance of class String.String objects created with the new operator do not refer to objects in the string pool but can be made to using String's intern() method. The java.lang.String.intern() returns an interned String, that is, one that has an entry in the global String pool. If the String is not already in the global String pool, then it will be added.
Posted in: