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

does String take a fixed size in memory?

 
Maha Hassan
Ranch Hand
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • 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??
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Clojure Spring VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic