字符串类型的数组转怎么换成整数类型的数组

2024-11-15 19:37:40
推荐回答(2个)
回答1:

a = "123,456,789";
b = a.split(",");
c = [];
for (var i = 0; i < b.length; i++) {
    c.push(Number.parseInt(b[i]));
}
console.log(c);

回答2:

public static void main(String[] args) throws Exception {

String str="12345";
int arr[] = new int[str.length()];
for (int i = 0;i < str.length(); i ++)
{
arr[i] = Integer.parseInt(str.substring(i,i+1));
System.out.println(arr[i]);
}

}