创建一个动态的二维矩阵中的Java矩阵、创建一个、动态、Java

2023-09-07 13:10:33 作者:奋斗吧〆少年°

我想要一个动态矩阵,数量的行和列unkonw,通过点击一个按钮填充它。卜有更多的:我不希望添加整个行,但只有一个单元的时候,点击=一个细胞增加。当然不是随机:1行1列第2小区......然后是同样的第2行等一第1单元...

I want a dynamic matrix, number rows and columns unkonw, filling it by clicking on a button. Bu there is more: I don't want to add entire rows, but just one cell at the time, one click = one cell added. Of course not randomly : 1st cell of 1st row, 2nd cell of 1st row... and then the same of the 2nd row and so one...

我知道UJMP,ArrayList的,但它不是我要找相当的东西。请准确对您的回答,谢谢你在前进。

I know about UJMP, ArrayList, but it's not quite what I'm looking for. Please be accurate on your answer, thank you in advance.

推荐答案

使用这样的:

List<List<Integer>> dynamicMatrix = new ArrayList<List<Integer>>();

dynamicMatrix.add(new ArrayList<Integer>());
dynamicMatrix.add(new ArrayList<Integer>());
dynamicMatrix.add(new ArrayList<Integer>());

dynamicMatrix.get(0).add(6);
dynamicMatrix.get(0).add(7);
dynamicMatrix.get(0).add(8);

System.out.println(dynamicMatrix.get(0).get(0)); // 6
System.out.println(dynamicMatrix.get(0).get(1)); // 7
System.out.println(dynamicMatrix.get(0).get(2)); // 8