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 the purpose of the return statement?

512


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

530


why java uses class level type casting ?

2251


Explain the use of sublass in a java program?

596


how does multithreading take place on a computer with a single cpu? : Java thread

688






What is a arraylist in java?

553


Given a singly linked list, determine whether it contains a loop or not without using temporary space?

580


What is nullpointerexception?

552


What is oop in java?

522


What is the difference between the jdk 1.02 event model and the event-delegation model introduced with jdk 1.1?

610


Why is it important to initialize a variable?

489


What is the best definition for data?

517


Why java is said to be pass-by-value ?

544


What are structs in java?

567


Is a string literal?

521