How can I get the UTF8 code of a char in Java ? I have the char 'a' and I want the value 97 I have the char 'é' and I want the value 233
here is a table for more values
I tried Character.getNumericValue(a)
but for a it gives me 10 and not 97, any idea why?
This seems very basic but any help would be appreciated!
You can use the codePointAt(int index) method of java.lang.String for that. Here's an example:
If you want to avoid creating strings unnecessarily, the following works as well and can be used for char arrays:
This produces good result:
Likewise:
prints out
233
.Note that the first example only works for characters included in the standard and extended ASCII character sets. The second works with all Unicode characters. You can achieve the same result by multiplying the char by 1. System.out.println( 1 * 'é');