what is meant by string pooling?

Answer Posted / birendra kumar

String constant pool is part of the heap memory. which is
manage the memory efficient by the JVM.

if you create String literal like..
//suppose pool is empty..

// str(is reference variable) and abc(is String object)

String str="abc";

/*Creating on String object and one reference variable.
so abc is stored in pood and str is refered it. */

//if you created another String literal with same content like..
String str1="abc";

/* it is only creating reference variable which is point
same String object "abc". because of JVM is checking first
if any content with same string object in the pool just it
is make the reference not created new String object*/

if you creating String Object using new keyword like..

String str2=new String("abc");

/* creating two object and one reference variable*/
because here we used new keyword and it is creating normal
object in the heap(non pool)memory.where 1st object is
stored and str is refered to it. and 2nd object is stored as
it is in string pool.

that is reasion in java if you match with str with str2
using (==) operator it will give you false result because of
(==) operator is match basis of reference variable which is
pointing same object if you use equals method then you get
true.basis of content of the reference variable in .

Is This Answer Correct ?    15 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you compare objects in java?

695


When should I use a singleton?

771


What is jee6?

744


What are the methods available in a class?

825


design an lru cache in java?

740


Why does java not allow multiple public classes in a java file ?

3914


What is a null class?

767


Can a class have a static inner class?

812


Explain features of interfaces in java?

773


What are actual parameters?

734


What is command line argument

935


What is data structure in java?

728


What is the use of a conditional inclusion statement in Java ?

812


What are thread priorities and importance of thread priorities in java?

822


What is the relationship between class and object?

766