Creating Unicode character from its number

后端 未结 13 1810
挽巷
挽巷 2020-11-28 21:38

I want to display a Unicode character in Java. If I do this, it works just fine:

String symbol = \"\\u2202\";

symbol is equal to \"∂\". That\'

13条回答
  •  温柔的废话
    2020-11-28 22:16

    If you want to get a UTF-16 encoded code unit as a char, you can parse the integer and cast to it as others have suggested.

    If you want to support all code points, use Character.toChars(int). This will handle cases where code points cannot fit in a single char value.

    Doc says:

    Converts the specified character (Unicode code point) to its UTF-16 representation stored in a char array. If the specified code point is a BMP (Basic Multilingual Plane or Plane 0) value, the resulting char array has the same value as codePoint. If the specified code point is a supplementary code point, the resulting char array has the corresponding surrogate pair.

提交回复
热议问题