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
Is integer immutable in java?
What is passing parameters in java?
What is string pool in java?
How would overload a function based on return type?
Can a constructor call the constructor of parent class?
if u open login & logout ,how can udisplay the timelogin & logout members ?
Can private class be inherited in java?
What does java ide mean?
What is == mean?
What are multiple inheritances? Is it supported by java?
Explain java coding standards for variables ?
Can we serialize arraylist in java?
Can java arraylist hold different types?
Are strings immutable in java?
What causes memory leaks in java?