Java的:String.toCharArray()与UNI code字 [英] Java: String.toCharArray() with unicode characters
问题描述
我知道字符不能包含统一code字符(如字符c ='\\ u1023')。所以,我怎么会去这样做。
I know that char cannot contain Unicode characters (like char c = '\u1023'). So how would I go about doing
String s = "ABCDEFG\u1023";
char[] c = s.toCharArray();
我想送我必须通过每一个字符在可能很长的字符串这是低效转换为CharArray出于性能的考虑到循环。任何有达到同样的效果是好的。
I would like to convert s to a CharArray for performance reasons as I have to loop through every character in a potentially very long string which is inefficient. Anything which achieves the same result is fine.
非常感谢!
编辑:
其实字符可以包含单code字符。我只是愚蠢。由于这些反正谁帮助了。
Actually char can contain unicode chars. I'm just being stupid. Thanks to those who helped out anyway.
推荐答案
谁告诉你,在Java中字符
不能包含统一code字,<一个HREF =http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.1>错了:
Whoever told you that in Java char
can't contain Unicode characters, was wrong:
积分类型的值是整数在以下范围:
The values of the integral types are integers in the following ranges:
- 对于
字符
,从'\\ u0000的
到'\\ uffff
包容性,即从0到
65535
- For
char
, from'\u0000'
to'\uffff'
inclusive, that is, from 0 to 65535
这篇关于Java的:String.toCharArray()与UNI code字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!