Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

char to Unicode more than U+FFFF in java?

How can I display a Unicode Character above U+FFFF using char in Java?

I need something like this (if it were valid):

char u = '\u+10FFFF';
like image 962
liuyuqing Avatar asked Mar 23 '12 06:03

liuyuqing


People also ask

What does uFFFF mean in Java?

String str2 is assigned \uFFFF which is the highest value in Unicode. To convert them into UTF-8, we use the getBytes(“UTF-8”) method.

Why char uses 2 bytes in Java and what is u0000?

The 'char' data type in Java originally used for representing 16-bit Unicode. Therefore the size of the char data type in Java is 2 byte, and same for the C language is 1 byte. Hence Java uses Unicode standard. What are features of Java language?

Is Java char Unicode or ASCII?

Java actually uses Unicode, which includes ASCII and other characters from languages around the world.

How many characters can Unicode encode?

The maximum possible number of code points Unicode can support is 1,114,112 through seventeen 16-bit planes. Each plane can support 65,536 different code points. Among the more than one million code points that Unicode can support, version 4.0 curently defines 96,382 characters at plane 0, 1, 2, and 14.


1 Answers

You can't do it with a single char (which holds a UTF-16 code unit), but you can use a String:

// This represents U+10FFFF
String x = "\udbff\udfff";

Alternatively:

String y = new StringBuilder().appendCodePoint(0x10ffff).toString();

That is a surrogate pair (two UTF-16 code units which combine to form a single Unicode code point beyond the Basic Multilingual Plane). Of course, you need whatever's going to display your data to cope with it too...

like image 102
Jon Skeet Avatar answered Sep 28 '22 20:09

Jon Skeet