Java Convert char to intWe 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. 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 valueLet's see the simple code to convert char to int in java. Test it NowOutput: 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 NowOutput: 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 NowOutput: 1 Next TopicJava int to char |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India