Read Also: Convert ASCII to String in Java
What is Unicode in Java
According to Oracle docs, Unicode is a computing industry standard designed to consistently and uniquely encode characters used in written languages throughout the world. It uses hexadecimal to express a character as shown below in the examples. Unicode value of character J: \u004a
Unicode value of character H: \u0048
One-liner:
You can easily get the Unicode value of a Character by using the below one-liner code: String.format("\\u%04x", (int) ch);
Java Program: Get the Unicode value of a Character
Below is the Java program demonstrating how to find the Unicode value of a Character in Java: public class UnicodeCharacterValue {
public static void main(String args[]) {
String str = "Alive is Awesome";
char givenChar = str.charAt(2);
String unicode = getUnicodeValueOfChar(givenChar);
System.out.println("Unicode value of i is: " + unicode);
}
public static String getUnicodeValueOfChar(char ch)
{
return String.format("\\u%04x", (int) ch);
}
}
Output:
Unicode value of i is: \u0069
That's all for today. Please mention in the comments if you have any questions related to how to get the Unicode value of a Character in Java with examples.