File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference K&B P:420

 
Guru dhaasan
Ranch Hand
Posts: 126
Java Ubuntu VI Editor
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pinkal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic