That answers my question but I have some more doubts...
If I have a string "place" in the string pool and I say
"rlace".replace('r','p') doesnt the returned string point to the one already in the pool? Does it create a new reference like
String something=new String("place") ?
I have read in Rbert et el
===============
Java classes have a pool of strings.When a literal is compiled ,the compiler adds an appropriate string to the pool.However,if the same literal already appeared as a a literal elsewhere in class, then it is already represented in the pool.The compiler doesn't create a new copy,it uses the existing one from the pool.This saves on memory and can do no harm.
=====================
So .when it uses the same copy from the pool when it encounters the same string again elsewhere in the program,doesnt it use the same reference also ?
If I had code like this...
String s=new String("StrinG");
if("String",replace('g','G')=="StrinG")
{
}
What is the scenario like now?
What are the strings pointing to the literal pool?