Get Unicode Value of Character in Java

Get unicode value of character in java

In this post, we will see how to get unicode value of character in java.

Get Unicode Value of Character in Java

You can simply use below code to get unicode value of character in java.

Here is complete example to print unicode value of character in java:

Output

Unicode value of character d: \u0061
Unicode value of character क: \u0915

If source is not character but string, you must chatAt(index) to get unicode value of the character.

Output:

Unicode value of character d: \u0061

Get Unicode Character Code in Java

In java, char is a "16 bit integer", you can simply cast char to int and get code of unicode character.

Here is definition of char from Oracle:

The char data type is a single 16-bit Unicode character. It has a minimum value of ‘\u0000’ (or 0) and a maximum value of ‘\uffff’ (or 65,535 inclusive).

Here is complete example:

Unicode character code: 174
Unicode character code in hexa format: ae

That’s all about how to get unicode value of character in java.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *