Javaで数値のUnicodeを数値自体に変換するにはどうすればよいですか?
char c ='2';
int x =c;
// here x=unicode of 2, how can I put the 2 itself in x?
最も一般的な解決策は
int x = Character.digit(c, 10); // interpret c as a digit in base 10
最速の解決策は、悪い入力を処理するために何もしませんが、
int x = c - '0'; // subtracts the Unicode representation of '0' from c
使用する
int x = Character.getNumericValue(c);
また
int x = Integer.valueOf(String.valueOf(c));
Integer.valueOfは他のintとStringsしか処理できないため、2番目のアプローチでは2つの変換が必要であることに注意してください。