Java char数组为int
问题描述:
是否可以将包含数字的 char []
数组转换为
和 int
?
Is it possible to convert a char[]
array containing numbers into
an int
?
答
char []
是否包含组成数字的unicode字符这个数字?在这种情况下,只需从 char []
创建一个String并使用Integer.parseInt:
Does the char[]
contain the unicode characters making up the digits of the number? In that case simply create a String from the char[]
and use Integer.parseInt:
char[] digits = { '1', '2', '3' };
int number = Integer.parseInt(new String(digits));