我有一长串数字,
String strNumbers = "123456789";
Run Code Online (Sandbox Code Playgroud)
我需要得到一个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;
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:java.lang.NumberFormatException:对于输入字符串:""
我的猜测是我无法以这种方式拆分String.我尝试了各种各样的逃避或正则表达但没有任何作用.
有人可以帮忙吗?