小编jpl*_*jpl的帖子

从一串数字中获取一个int数组

我有一长串数字,

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.我尝试了各种各样的逃避或正则表达但没有任何作用.

有人可以帮忙吗?

java arrays string int split

1
推荐指数
2
解决办法
205
查看次数

标签 统计

arrays ×1

int ×1

java ×1

split ×1

string ×1