English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need to convert a char in java to an int... how can this be done?

2007-09-20 19:12:11 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

Let us start with the parse bit first
http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#parseInt(java.lang.String)

So you require a string. How do you convert a char to string?
Well take a look at the Character class and you will find this.
http://java.sun.com/javase/6/docs/api/java/lang/Character.html#toString(char)

So to convert a char to a string you use
Character.toString(charData)

Now put that with the parse and you are done.

2007-09-20 19:37:27 · answer #1 · answered by AnalProgrammer 7 · 1 0

Java Char To Int

2016-12-16 19:32:13 · answer #2 · answered by ? 4 · 0 0

Char To Int Java

2016-10-06 07:30:45 · answer #3 · answered by Anonymous · 0 0

RE:
How can you parse a char to int in java?
I need to convert a char in java to an int... how can this be done?

2015-07-31 00:51:30 · answer #4 · answered by ? 1 · 1 0

Assume that you have a character variable call "c", you can use the command:
int number = Character.digit(c,10);
DONE!

2007-09-20 22:22:02 · answer #5 · answered by Java LAMP 3 · 0 0

i think the easiest way is this:

char c = '9'
int i = Character.getNumericValue(c)

// prints out 9
System.out.println(i);

2007-09-21 01:42:00 · answer #6 · answered by rice kid 4 · 5 0

fedest.com, questions and answers