• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sizeof For Java

 
rini john
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to know if in java is it possible to know the size of a string as in java there is no sizeof() operater....

Thanks
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The short answer is 'no' but you might get a different answer if you explain why you think you need this.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String.length(). However it will depend on the encoding you're using what the actual number of bytes is (that get written to a stream).
 
rini john
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In our application we want process a message which is a string but application can not process message which are more than 32 KB size.So for this we need to check the size of the message.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rini john wrote:In our application we want process a message which is a string but application can not process message which are more than 32 KB size.So for this we need to check the size of the message.


may be what you need. I would suggest that you use "utf-8" for the encoding but depending on the language you are processing you may find another encoding gives you a shorter resulting set of bytes.
 
Matthew Brown
Bartender
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String has a few getBytes() methods, that will return a byte array given a character set. You can then get the length of it.

Edit: or what James said .
 
rini john
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic