1 回答
TA贡献1825条经验 获得超4个赞
我稍微改变了你的算法。在这里,if (j < removeRow.length && removeRow[j][0] == i)我们找到要删除的行并且什么都不做,只是j在else块中增加,否则在rowsToKeep列表中添加行。
试试这个:
double[][] test = { {100}, {200}, {300}, {400}, {500}, {600}, {700}, {800}, {900}, {1000} };
int[][] removeRow = { {0}, {1}, {3}, {4} };
int j = 0;
List<double[]> rowsToKeep = new ArrayList<>(test.length);
for (int i = 0; i < test.length; i++) {
if (j < removeRow.length && removeRow[j][0] == i) {
j++;
} else {
double[] row = test[i];
rowsToKeep.add(row);
}
}
test = new double[rowsToKeep.size()][];
for (int i = 0; i < rowsToKeep.size(); i++) {
test[i] = rowsToKeep.get(i);
}
System.out.println(Arrays.deepToString(test));
添加回答
举报