Java Program to Convert Char to Int

Last Updated : 18 Aug, 2026

Given a char value, we can convert it into an int value in Java using type casting or methods provided by the String and Character classes. The appropriate method depends on whether we want the character's Unicode value or its numeric digit value.

  • Character.getNumericValue() directly returns the numeric value represented by the character.
  • Integer.parseInt() throws NumberFormatException when the character does not form a valid decimal number.

Illustration

Input : ch = '3'
Output : 3

Input : ch = '9'
Output : 9

Methods to Convert Char to Int in Java

There are numerous approaches to the conversion of the Char datatype to the Integer (int) datatype. A few of them are listed below.

1. Using Type Casting

A char can be directly converted to an int using type casting. However, direct casting gives the Unicode value of the character, not necessarily its numeric digit value.

Syntax:

int value = (int) ch;

Java
// Using Type Casting

public class Geeks {
    public static void main(String[] args) {

        char ch = '3';

        // Convert char to int
        int value = (int) ch;

        System.out.println("char value: " + ch);
        System.out.println("int value: " + value);
    }
}

Output
char value: 3
int value: 51

Explanation: The character '3' has Unicode value 51, so casting it to int produces 51.

2. Using String.valueOf() and Integer.parseInt()

String.valueOf() can convert the character into a String, and Integer.parseInt() can then convert that numeric string into an int.

Syntax:

int value = Integer.parseInt(String.valueOf(ch));

Java
// Using String.valueOf() and Integer.parseInt()

public class Geeks {
    public static void main(String[] args) {

        char ch = '3';

        // Convert char to String and then to int
        int value = Integer.parseInt(String.valueOf(ch));

        System.out.println("char value: " + ch);
        System.out.println("int value: " + value);
    }
}

Output
char value: 3
int value: 3

Explanation: String.valueOf(ch) converts '3' into the string "3". Then Integer.parseInt() converts "3" into the integer 3.

3. Using Character.getNumericValue()

The Character.getNumericValue() method returns the numeric value represented by a character. It can handle numeric characters as well as certain letters that represent numeric values.

Syntax:

int value = Character.getNumericValue(ch);

Java
// Using Character.getNumericValue()

public class Geeks {
    public static void main(String[] args) {

        char ch = '3';

        // Get numeric value of the character
        int value = Character.getNumericValue(ch);

        System.out.println("char value: " + ch);
        System.out.println("int value: " + value);
    }
}

Output
char value: 3
int value: 3

Explanation: Character.getNumericValue('3') returns 3, which is the numeric value represented by the character.

Comment