Comparing a char to a code-point?

前端 未结 5 1726
不知归路
不知归路 2020-12-01 02:15

What is the \"correct\" way of comparing a code-point to a Java character? For example:

int codepoint = String.codePointAt(0);
char token = \'\\n\';
<         


        
5条回答
  •  伪装坚强ぢ
    2020-12-01 02:42

    For characters in the basic multilingual plane, casting the char to an int will get you the codepoint. This corresponds to all the unicode values that can be encoded in a single 16 bit char value. Values outside this plane (with codepoints exceeding 0xffff) cannot be expressed as a single character. This is probably why there is no Character.toCodePoint(char value).

提交回复
热议问题