我是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
}
}
Run Code Online (Sandbox Code Playgroud)
我看到了答案,但它们必须是固定大小的,例如:
ArrayList<String>[][] list = new ArrayList[10][10];
Run Code Online (Sandbox Code Playgroud)
但是,我希望不同对象的列表L的大小不同.还有其他选项,比如copyOf,但上述功能是否可以通过这个数组实现?