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 is the purpose of the return statement?
can java object be locked down for exclusive use by a given thread? Or what happens when a thread cannot acquire a lock on an object? : Java thread
why java uses class level type casting ?
Explain the use of sublass in a java program?
how does multithreading take place on a computer with a single cpu? : Java thread
What is a arraylist in java?
Given a singly linked list, determine whether it contains a loop or not without using temporary space?
What is nullpointerexception?
What is oop in java?
What is the difference between the jdk 1.02 event model and the event-delegation model introduced with jdk 1.1?
Why is it important to initialize a variable?
What is the best definition for data?
Why java is said to be pass-by-value ?
What are structs in java?
Is a string literal?