Java how to get unicode value of a character, and String character


The char data type is a single 16-bit Unicode character. If we need to know the unicode value represented by the character we have several options. Following covers some of the options
To get Unicode of a character
If we want to know the unicode value for '1', we can use Integer.toString()
char myChar = '1';
String unicode = Integer.toString(myChar);
System.out.print(unicode); // Prints 49
To get Unicode of a character of a String
If we want to know the unicode value for "1", we can use Integer.toString()
String inputString = "1";
int unicodeFromString = inputString.codePointAt(0);
System.out.print(unicodeFromString); // Prints 49

No comments :

Post a Comment

Please leave your message queries or suggetions.