在java中删除2D arraylist中的特定行

时间:2021-10-17 21:37:34

I want to delete a specific row from 2D arraylist and that row is replaced by the next row. I wrote following code:

我想从2D arraylist中删除一个特定的行,该行将被下一行替换。我写了以下代码:

Collection<?> c = joint_mat.get(row); joint_mat.get(row).removeAll(c);

集合 c = joint_mat.get(row); joint_mat.get(行).removeAll(C);

This code is deleting the elements of the row but not replacing it with the next row. Output is as follows:

此代码正在删除行的元素,但不会将其替换为下一行。输出如下:

[0.6, 0.608, 0.608, 0.628, 0.608],

[0.6,0.608,0.608,0.628,0.608],

[0.6, 0.6, 0.6, 0.608, 0.608],

[0.6,0.6,0.6,0.608,0.608],

[0.6, 0.652, 0.6, 0.612, 0.608],

[0.6,0.652,0.6,0.612,0.608],

[],

[0.612, 0.632, 0.608, 0.604, 0.608],

[0.612,0.632,0.608,0.604,0.608],

[0.6, 0.604, 0.604, 0.62, 0.62],

[0.6,0.604,0.604,0.62,0.62],

1 个解决方案

#1


0  

How about this:

这个怎么样:

joint_mat.remove(row);

P.S. an easier way to do what you are doing above, clearing the contents of the arraylist on the row, is like this:

附:一个更简单的方法来做你正在做的事情,清除行上的arraylist的内容,是这样的:

joint_mat.get(row).clear();

#1


0  

How about this:

这个怎么样:

joint_mat.remove(row);

P.S. an easier way to do what you are doing above, clearing the contents of the arraylist on the row, is like this:

附:一个更简单的方法来做你正在做的事情,清除行上的arraylist的内容,是这样的:

joint_mat.get(row).clear();