Hi Guys,
Again I am here with new question. Have a discussion with my
friends and little bit confused about the string pool.
If I am creating a String object using
String obj1="shiv";
and
String obj2 = new String("shiv");
We know "shiv" will go in string pool. And when multiple objects created
like
String obj3 = "shiv";
String obj4 = "shiv";
then (obj3==obj4) and (obj1==obj4) will return true because they are
pointing to same object.
Now
If I created object
String obj5 = new String("shiv");
Here (obj2==obj5) will return false and (obj5==obj1) will return false.
It means both object obj2 and obj5 are different. But what about string
literal "shiv". Where it will reside in this case. Will it like
obj2 and obj5 are two different objects in Heap but internally they are
pointing to same object "shiv" on string pool.
Or
its like cloning of object with "shiv" string. And having two totally
different objects in Heap memory.
What about
String x = "shiv";
String y = new String(x);
String z = new String (y);
Here I think if I called a method on z object it will call same method
from y and then method of y will call same method of x and then finally
x will call method of String pool "shiv" object.
Correct me where I am wrong.
Thanks
Shiv Shankar
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en