Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

String pool

PremFeb 16 2011 — edited Feb 17 2011
Hi

Consider following snippet of code

1. String s1="Hello";
2. String s2=new ("Hello");
3. String s3=new ("Hello");
4. SOP(s1==s2)
5. SOP(s2==s3)


Above line 4 and 5 returns false because s1 refers to a string in string pool where as s2 and s3 refers to string in heap .

I am having confusion on following code


1. String s1="Hello";
2. String s2=new ("Hello");
3. String s3=new ("Hello");
4. s1=s3;

i just want to know that s1 is now pointing to a string created into heap by s3.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 17 2011
Added on Feb 16 2011
12 comments
314 views