Nested ArrayList

arraylist, java

Solution

I suggest to create classes for page and rows.

Internaly they can hold their children in a list:

public class Row {
    List<String> rowContent;
    Page parent;

    //...
}



public class Page {
    List<Row> rows;

    //...
}

Problem

I have a 3 level nested arrayList as follows: ``` ArrayList<String> rowContents = new ArrayList(); ArrayList<ArrayList<String>> rows; ArrayList<ArrayList<ArrayList<String>>> page; ``` In the code, within different loops, the arrayLists will be populated as follows: ``` rowContents.add("some content"); rows.add(rowContents); page.add(rows); ``` Is it okay to use 3 level nested arrayLists like this? Or, is there a better approach?

Original source