创建一个动态的二维矩阵中的Java [英] Creating a dynamic 2D matrix in Java

查看:341
本文介绍了创建一个动态的二维矩阵中的Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个动态矩阵,数量的行和列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

这篇关于创建一个动态的二维矩阵中的Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆