Generic type for Arraylist of Arraylists

前端 未结 5 680
长情又很酷
长情又很酷 2021-01-02 12:54

In normal array list initialization, We used to define generic type as follows,

List list1 = new ArrayList();

B

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-02 13:58

    Something like this:

    List> matrix = new ArrayList>();
    for (int i = 0; i < numRows; ++i) {
        List row = new ArrayList();
        // add some values into the row
        matrix.add(row);
    }
    

    Make the type of the inner List anything you want; this is for illustrative purposes only.

提交回复
热议问题