user2097804 user2097804 - 8 months ago 66
Java Question

Two Dimensional ArrayList

I know that I can add a dimension to an array by adding another [] beside it. But can I have more than one Dimension in a java.util.ArrayList? How might I accomplish this?


Yes, it's possible. Just have the elements of your ArrayList also be ArrayLists.

ArrayList<ArrayList<Integer>> twoDArrayList = new ArrayList<ArrayList<Integer>>();

This would work with not just ArrayLists, but other collection types as well.