我是Java的新手,尝试创建一个大小不固定的二维列表。我的代码如下:
public class q1 {
List<List<Integer> > L = new ArrayList<List<Integer> >();
public void set(int m,int n){
//This is the function which would get the size of the 2d list
}
}
我看到了答案,但它们必须具有固定的尺寸,例如:
ArrayList<String>[][] list = new ArrayList[10][10];
但是,我希望对于不同的对象,列表L能够有不同的大小。虽然还有其他选项,例如copyOf,但是仅凭这个数组就能实现上述功能吗?