Printing Unicode in Java

I need to print Unicodes of A-Z in Java.

How do I print the Unicode of a character in Java?

13.10.2009 17:05:20
3 ОТВЕТА
РЕШЕНИЕ

int CharCode = (int)'a';

Or:

System.out.println((int)'a');

So for your example:

for (char c='A'; c <= 'Z'; c++)
{
    System.out.println(c + ": " + (int)c);
}
2
13.10.2009 17:13:35

You could use the Character class.

5
13.10.2009 17:08:05

If you are interested in the unicode numbers of the letters you can do the following (here for the letter 'x'):

byte[] bytes = "x".getBytes( "UTF-16" );

System.out.println( String.format("%0" + (bytes.length * 2) + "X", 
    new BigInteger( 1, bytes )) );

This will output:

FEFF0078

For UTF-8 and other letters simply change the first line.

0
13.10.2009 17:22:09
I think I've never seen such a bloated and even incorrect implementation of (int)'x'.
jarnbjo 13.10.2009 19:58:30