In java,<\/i>
char ch = '\u00A5'; // '¥'
You cannot do that with a single char constant, since a char is a UTF-16 code unit. You have to use a String constant, such as:
final String s = "\uXXXX\uYYYY";
where XXXX
is the high surrogate and YYYY
is the low surrogate.
Another solution is to use an int
to store the code point; you can then use Character.toChars()
to obtain a char[]
out of it:
final int codePoint = 0x1f4ae; // for instance
final char[] toChars = Charater.toChars(codePoint);
Depending on what you use, you may also append code points directly (a StringBuilder
has a method for that, for instance).
To avoid writing surrogates pair for non-BMP chars and obtaining a String from a code point there are several methods.
String test1 = new String(new int[] { 0x1f4ae }, 0, 1);
String test2 = String.valueOf(Character.toChars(0x1f4ae));
String test3 = Character.toString(0x1f4ae):
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.