• Post Reply Bookmark Topic Watch Topic
  • New Topic

Null String  RSS feed

 
Shripad Katkamwar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As we all know empty string takes 40 bytes in memory.Could anyone tell me please,how much byte null string takes?
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

By 'null' string, what we mean is - a reference of type String, which does not refer to any String object.

Since it does not refer to any object, the question about 'how big the object is' is irrelevant.

I hope this helps.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shripad Katkamwar wrote:As we all know empty string takes 40 bytes in memory. . . .
How do you know?

And welcome again
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Shripad Katkamwar wrote:As we all know empty string takes 40 bytes in memory. . . .
How do you know?

And actually, I suspect the statement is wrong, because will take up a different amount of space on a 64-bit machine to a 32-bit one.

Also: If declared or supplied as a literal (""), it will be shared, so the number of bytes it takes up really isn't worth obsessing about, because it will only be created once.

HIH

Winston
 
Paul Clapham
Sheriff
Posts: 22834
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Shripad Katkamwar wrote:As we all know empty string takes 40 bytes in memory. . . .
How do you know?


Actually I didn't know that. While programming Java for over 10 years I never found it necessary to care about that sort of thing. Like Winston just said, it isn't worth knowing.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!