Web Development Blog

24K Design Studio :: Blog :: Maybe a bug in java6 String.length?
Author:
Password:
Maybe a bug in java6 String.length?
22:56, 28 Mar, 2012
by David

When a character is larger than 0xffff, java's String.length cannot output it correctly in at least java6.

In the page "http://en.wikipedia.org/wiki/UTF8" which explains UTF8, there is a character "𤭢". This character is larger than 0xffff in Unicode.

Java's String.length works usually well for Unicode characters, like "好", which has length 1. However, if you try that special character "𤭢" it will return 2. By using String.getBytes(Charset.forName("UTF-8")), we can see that the string is stored correctly and can be exported in someway like getBytes, so it implies that the problem is actually happened in length function.

Reply:
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 =

Reply
#1
gatbmqhg
05:03, 25 Nov, 2015
 
1
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 =

Reply
View the latest 5 entries.