[英]Deleting specific row in 2D arraylist in java
I want to delete a specific row from 2D arraylist and that row is replaced by the next row. 我想从2D arraylist中删除特定的一行,然后将该行替换为下一行。 I wrote following code:
我写了以下代码:
Collection<?> c = joint_mat.get(row); joint_mat.get(row).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],
How about this: 这个怎么样:
joint_mat.remove(row);
PS an easier way to do what you are doing above, clearing the contents of the arraylist on the row, is like this: PS是一种更简单的方法来执行上述操作,清除行上arraylist的内容,如下所示:
joint_mat.get(row).clear();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.