tags:

views:

134

answers:

3

Hi all

I need to print unicodes of A-Z in java.

How do i print the unicode of a character in java.

Abdul khaliq

+4  A: 

You could use the Character class.

Thomas Owens
+2  A: 

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);
}
asveikau
A: 

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.

tangens
I think I've never seen such a bloated and even incorrect implementation of `(int)'x'`.
jarnbjo