【发布时间】:2013-04-10 14:00:27
【问题描述】:
我有一长串数字,
String strNumbers = "123456789";
我需要从这里获得int[]。
我用这个方法得到它:
public static int[] getIntArray(strNumbers)
{
String[] strValues = strNumbers.split("");
int[] iArr = new int[strValues.length];
for(int i = 0; i < strValues.length; i++)
{
iArr[i] = Integer.parseInt(strValues[i]);
}
return iArr;
}
我收到此错误:java.lang.NumberFormatException: For input string: ""
我的猜测是我不能那样拆分字符串。我尝试了各种转义或正则表达式,但没有任何效果。
谁能帮忙?
【问题讨论】:
-
感谢编辑。总有一天我会做对的。 ;)
标签: java arrays string split int