Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

String, encoding and bytes length....

807580Jan 14 2010 — edited Jan 14 2010
Hi All,
I'd like to know if there is a way to establish how many bytes a string required with a specific encoding without to convert it in bytes.
In few words I need to know lenInBytes but I want to avoid string to bytes conversion in order to reduce memory usage:
String s = "this is my string that can contain not ascii chars";
int lenInBytes  = s.getBytes().length;   // using default charset
Thanks a lot
ste
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 11 2010
Added on Jan 14 2010
9 comments
787 views