Forums Register Login

Sizeof For Java

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
The short answer is 'no' but you might get a different answer if you explain why you think you need this.
1
+Pie Number of slices to send: Send
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).
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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 .
+Pie Number of slices to send: Send
thanks......
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 902 times.
Similar Threads
memory allocation
Find the data type of a variable
difference between exe file and batch file
Size of an Object
size-of primitive in java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:50:00.