我有一个数组列表,看起来像:
private ArrayList<ArrayList<Integer>> matrix = new ArrayList<ArrayList<Integer>>(9);
它充满了这些元素:
[[7], [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9], [3], [1, 2, 3, 4, 5, 6, 7, 8, 9], [4], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9]]
现在我想从第二个索引中删除“1”,所以我想要的输出是:
[[7], [2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9], [3], [1, 2, 3, 4, 5, 6, 7, 8, 9], [4], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9]]
但是当我在表单中使用 remove 方法时:
matrix.get(1).remove(0);
输出是:
[[7], [2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5, 6, 7, 8, 9], [3], [2, 3, 4, 5, 6, 7, 8, 9], [4], [2, 3, 4, 5, 6, 7, 8, 9], [9]]
您可以看到主 ArrayList 的所有 ArrayLists 中的每个“1”都被删除,而不是仅在第二个索引处。如何更改我的代码,以便只删除第二个索引的“1”?