• 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

Strings and the string constant pool

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In K&B, they describe the following two statements as having different meanings:


They say the first one creates one String literal object in the pool and one reference, while the other one creates a String literal object in the pool, a String() object on the heap, and a String reference variable.

I understand what they are saying, but what is the fundamental difference here? Why does this happen, and what are the reasons for/implications of this?

Thanks very much!!
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try Corey's article Strings Literally for starters. From my point of view the main purpose of the string pool is to conserve memory requirements in programs which require the use of many constant strings. On the other hand, you may need a fresh copy of a String if you are making a deep copy of a compound object which has String valued members.
 
reply
    Bookmark Topic Watch Topic
  • New Topic