• 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

String and boolean memory

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe each character in a String uses two bytes of memory, even whitespace characters.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
------------------
 
reply
    Bookmark Topic Watch Topic
  • New Topic