2009-08-13

Java: char to int

Today I found some code (in a current project of a company), where they convert a Java char to an int like this:

int x = Integer.parseInt( String.valueOf( c ) );

where c is a char like '0', '1', ... (i.e. a digit as a char).

I would suggest to make a conversion like:

int x = c - '0';

That's easier and probably faster...

No comments:

Post a Comment