get char value in java

后端 未结 8 1653
孤街浪徒
孤街浪徒 2020-12-18 20:04

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

8条回答
  •  醉酒成梦
    2020-12-18 20:52

    You can use the codePointAt(int index) method of java.lang.String for that. Here's an example:

    "a".codePointAt(0) --> 97
    "é".codePointAt(0) --> 233
    

    If you want to avoid creating strings unnecessarily, the following works as well and can be used for char arrays:

    Character.codePointAt(new char[] {'a'},0)
    

提交回复
热议问题