This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference K&B P:420

 
Guru dhaasan
Ranch Hand
Posts: 126
Java Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In K&B P:420 it is given as

String s="abc";

String s=new String("abc");

And its said that these will create 2 objects and 1 reference

My Question is:
Since the two strings points to same content what is the need for creating two objects. Wont the string constant pool checks this.........


Thanks in Advance
 
Pinkal Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you are using new String("123");

Will create unother Object without cheaking the Pool.


and when unig s="123";

It will first check pool and create object if it is not found in the Pool

May be this will clear your doubt.
 
Guru dhaasan
Ranch Hand
Posts: 126
Java Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pinkal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic