aspose file tools*
The moose likes Beginning Java and the fly likes String and boolean memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String and boolean memory" Watch "String and boolean memory" New topic
Author

String and boolean memory

Amr Khan
Greenhorn

Joined: Jul 27, 2001
Posts: 6
Q1) How do I know that the String text below occupies how much memory?
String text=" My name is Tom. ";
Q2) What is the memory occupied by a boolean?

Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
If you actuallu meant memory, I don't know how much or why you would need to know it anyway. As for size, use the length() method on the string. I believe a boolean is 1 bit in size.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Jason Ford
Ranch Hand

Joined: Aug 02, 2001
Posts: 54
Actually, a boolean is probably stored as a byte. Though this is an inefficient use of memory, the complications involved in addressing a single bit of memory more than justify this implementation.


SCJP, SCWCD
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
I believe each character in a String uses two bytes of memory, even whitespace characters.
Noorulain Khan
Greenhorn

Joined: Jul 31, 2001
Posts: 28
Hi,
String:
is a Non-primitive data type and in actual is array.
Array is like we stack stuff somewhere with Last in First Out method. Likewise the data is stored in memory with the same method Byte by Byte. Therefore the size will vary depending upon the characters are given in a string.
However if you would want to know about the size of the string variable (veryuseful in programming as well) you can use
length() method.
Boolean:
In java the length and code both are not described anywhere and
at all.
But through studies i guess it occupies the least memory of rest of the datatypes.
------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String and boolean memory