How to get ASCII value of a char in Java?

To get ASCII value of a char in Java, either cast it to int or assign it to an int variable.

Here's how you do it:

char x = 'X';

int asciiOfX = x;

System.out.println(asciiOfX); // 88
System.out.println((int)x); // 88