• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

difference K&B P:420

 
Ranch Hand
Posts: 126
VI Editor Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
VI Editor Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pinkal
reply
    Bookmark Topic Watch Topic
  • New Topic