what is meant by string pooling?

Answer Posted / indrajit yadav

A string pool is a collection of references to String
objects."String Literal Pool" still live on the heap memory,
but they have references to them from the String Literal Pool.

See the below example:
public class Program {
public static void main(String args[]){
//String literal will store in String pool
String s1="Indrajit";//case 1
String s2="Indrajit";//case 2
//In case 1, iteral s1 is created newly and kept in the
pool. But in case 2, literal s2 refer the s1, it will not
create new one instead
//String object
String s = new String("hi");
String ss = new String ("hi");
if (s1==s2){
System.out.print("equal");//print equal
}
/*
if(s==ss){
System.out.print("Reference are not equal");//no ouptput
}
*/
}
}

Is This Answer Correct ?    24 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is null an object java?

749


Is it possible to compare various strings with the help of == operator?

765


whatis Home interface and Remoteinterface? with example?

1767


How destructors are defined in java?

899


How hashset works internally in java?

798


What is a nested list?

749


What is numel matlab?

1012


what is function overloading in java?

960


Is set thread safe java?

707


Explain the difference between intermediate and terminal operations in java8?

806


Which is the best sorting technique in java?

755


What is meant by class?

775


What is difference between variable declaration and definition?

748


What does file separator do in java?

752


What is meant by JVM? Is JVM platform independent or not?

837