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

What is difference between arraylist and list in java?

842


What is the diffrence between inner class and nested class?

842


What is Gang of four design patterns

833


What are methods in java?

778


What does super keyword do?

800


How do you create a first line indent?

751


How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?

823


Why do we need singleton?

762


what is the difference between thread and runnable types? : Java thread

793


How do I type unicode?

749


How big is a 32 bit integer?

789


What is meant by null and void?

762


What classes of exceptions may be caught by a catch clause in java programming?

966


What about main() method in java ?

786


What is navigable map in java?

772