Javatpoint Logo
Javatpoint Logo

Java Convert char to int

We can convert char to int in java using various ways. If we direct assign char variable to int, it will return ASCII value of given character.

Java Convert char to int

If char variable contains int value, we can get the int value by calling Character.getNumericValue(char) method. Alternatively, we can use String.valueOf(char) method.

1) Java char to int Example: Get ASCII value

Let's see the simple code to convert char to int in java.

Test it Now

Output:

97
49

2) Java char to int Example: Character.getNumericValue()

Let's see the simple code to convert char to int in java using Character.getNumericValue(char) method which returns an integer value.

Test it Now

Output:

1

3) Java char to int Example: String.valueOf()

Let's see another example which returns integer value of specified char value using String.valueOf(char) method.

Test it Now

Output:

1
Next TopicJava int to char





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA