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

Why string objects are immutable in java?

563


What is difference between filereader and bufferedreader?

527


What is a conditional equation?

558


What is entry set in java?

527


Can bool be null?

516






Which method must be implemented by all threads?

715


Is 0 an irrational number?

595


What are the methods to rectify ambiguities in the interfaces in JAVA?

582


What is keyword and identifier?

631


What is the difference between JDK and JVM?

627


How do you escape sequences in java?

588


How to check if linked list contains loop in java?

453


How can an exception be thrown manually by a programmer?

504


What is an immutable class?

608


How to disable caching on back button of the browser?

519