Henry Thompson Henry Thompson - 7 months ago 69
Java Question

Java: String.toCharArray() with unicode characters

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();

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.

Thanks a lot!

Actually char can contain unicode chars. I'm just being stupid. Thanks to those who helped out anyway.


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:

  • For char, from '\u0000' to '\uffff' inclusive, that is, from 0 to 65535