I have seen Questions and Answers about obtaining the code point number of a Unicode character in Java. For example, the Question How can I get a Unicode character's code?.
But I want the opposite: given an integer number, how do I get text of that character assigned to that code point number?
The char
primitive data type is of no use, being limited to only the Basic Multilingual Plane of the Unicode character set. That plane represents approximately the first 64,000 characters defined in Unicode. But Unicode has grown to nearly double that, over 113,000 characters defined now. The numbers assigned to characters range over a million. Being based on 16-bits, a char
is limited to a range of 64K, not nearly enough.
Both Character
and String
classes offer the method codePointAt
to examine a character and return an int
representing the code point assigned in Unicode. I am looking for the opposite.
➥ Given an int
, how to get an object of Character
, String
, or some implementation of CharSequence
that I can then join to other text?
When writing string literals, we can use a Unicode escape sequence with the backslash-with-u. But I am interested in working with integer variables, soft-coding rather than hardcoding the Unicode characters.