We can convert char to ASCII in Java by saving the char value as an int.
package org.code2care.examples;
public class CharToAsciiExample {
public static void main(String[] args) {
char c = 'z';
int charToAscii = c;
System.out.println(charToAscii);
}
}
Output: 122

From Java 8 or above we can make use of the getNumericValue(char) static method to get the numeric value associated with the given character according to Unicode specifications.
Example:public class CharToUnicodeValueExample {
public static void main(String[] args) {
char c = 'A';
int charToAscii = Character.getNumericValue(c);
System.out.println(charToAscii);
}
}
Output: 10
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!