How to Convert Char to Int in Java?

Use direct cast: `(int) ch`

Use `Character.getNumericValue(ch)` for digit characters and some letters

Use `Character.digit(ch, 10)` for base-10 digit characters

Use arithmetic with `’0’`: `ch – ‘0’` for numeric digits

Use `Integer.valueOf(String.valueOf(ch))` for a single digit character as a string

Use `String.valueOf(ch).charAt(0)` only if converting through string is needed

Suggested for You

Trending Today