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
What java ide should I use?
What checkbox method allows you to tell if a checkbox is checked?
How to stop a thread in java? Explain about sleep () method in a thread?
When should you make a function static?
What is maximum size of arraylist in java?
What's the purpose of static methods and static variables?
How to provide security in java
What is final keyword in java?
What does those terms actually mean included in the j.d.k i.6?
Which java version is latest?
What is difference between static class and normal class?
Can a set contain duplicates?
What is difference between printf and scanf?
What is broken and continue statement?
What does 0 mean in boolean?