一、作业要求
1、将数组字符串转成二维数组
2、字符串
"[[1,2,3],[3,4,5]]"
3、依赖hutool
二、代码
public static void main(String[] args) {标签:Java,int,++,二维,inneis,vals,java,array,inneiVals From: https://blog.51cto.com/u_15891242/5885717
String str = "[[1,2,3],[3,4,5]]";
JSONArray array = JSONUtil.parseArray(str);
int[][] vals = new int[2][3];
for (int i = 0; i < array.size(); i++) {
JSONArray inneis = array.getJSONArray(i);
for (int j = 0; j < inneis.size(); j++) {
vals[i][j] = (int)inneis.get(j);
}
}
for (int i = 0; i < vals.length; i++) {
int[] inneiVals = vals[i];
for (int j = 0; j < inneiVals.length; j++) {
System.out.println(inneiVals[j]);
}
}
}