• 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

does String take a fixed size in memory?

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i have String name ="Maha";
and String line ="this is a nice day";
do both take the same space in the memory??
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if i have String name ="Maha";
and String line ="this is a nice day";
do both take the same space in the memory??


I can see several ways to read that question, but the answer to each is "No".
 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what if i have an array of strings ,
how will it memory be alocated and each element take a different size
 
Steve Morrow
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what if i have an array of strings ,
how will it memory be alocated and each element take a different size


An "array of strings" is allocated as a special kind of object consisting of n elements. Those elements are String references (e.g., "pointers" to the String objects), not the String objects themselves.

One of the "nice" things about Java is that you don't have to manage this allocation (or any memory, for that matter). The JVM takes care of the nasty details.
[ September 06, 2005: Message edited by: Steve Morrow ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic