2D dynamic array using ArrayList in Java

后端 未结 9 1587
执笔经年
执笔经年 2021-01-06 07:02

I need to implement a 2D dynamic array. The number of rows is fixed, say n. But the number of columns for each row is not fixed and equivalent. For instance, the first row h

9条回答
  •  北海茫月
    2021-01-06 07:04

    How about List> ?

    For Example:

    List> list = new ArrayList>();
    
    List row1 = new ArrayList();
    row1.add(new Foo());
    row1.add(new Foo());
    row1.add(new Foo());
    list.add(row1);
    
    List row2 = new ArrayList();
    row2.add(new Foo());
    row2.add(new Foo());
    
    list.add(row2);
    

提交回复
热议问题