File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes does String take a fixed size in memory? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "does String take a fixed size in memory?" Watch "does String take a fixed size in memory?" New topic
Author

does String take a fixed size in memory?

Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
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

Joined: May 22, 2003
Posts: 657

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

Joined: Aug 02, 2005
Posts: 133
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

Joined: May 22, 2003
Posts: 657

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: does String take a fixed size in memory?