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!
EDIT: Actually char can contain unicode chars. I'm just being stupid. Thanks to those who helped out anyway.
The java string toCharArray() method converts the given string into a sequence of characters. The returned array length is equal to the length of the string. Syntax : public char[] toCharArray() Return : It returns a newly allocated character array.
Unicode is a 16-bit character encoding system. The lowest value is \u0000 and the highest value is \uFFFF. UTF-8 is a variable width character encoding. UTF-8 has the ability to be as condensed as ASCII but can also contain any Unicode characters with some increase in the size of the file.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With