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!

Difference between creating String object with new operator & literal pool

812848Dec 15 2010 — edited Dec 15 2010
Hi,

Can anyone please help me to understand what's the difference between following string object creation -

1. String s = new String("hi");
2. String s = "hi";

what i know is in first case a new object will be created and will be in heap memory and in the second case object will be in string literal pool which is also inside heap memory.

thanks in advance,
Sikky
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 12 2011
Added on Dec 15 2010
2 comments
1,058 views