Here's a way to get multi dimension ArrayLists:
In Java, you unfortunately can't create arrays of generics. However, ArrayList is basically an array, so create an ArrayList of ArrayLists.
Here's a few basic operations on a 2d ArrayList (easily extended to any dimension).
Java Code:
public class ArrayList2d<Type>
{
ArrayList<ArrayList<Type>> array;
public ArrayList2d()
{
array = new ArrayList<ArrayList<type>>();
}
public void ensureCapacity(int num)
{
array.ensureCapacity(num);
while (rows >= array.size())
{
array.add(new ArrayList<Type>());
}
}
public void ensureCapcity(int row, int num)
{
ensureCapacity(row);
array.get(row).ensureCapacity(num);
}
public void Add(Type data, int row)
{
ensureCapacity(row);
array.get(row).add(data);
}
public Type get(int row, int col)
{
return array.get(row).get(col);
}
public void remove(int row, int col)
{
array.get(row).remove(col);
}
public boolean contains(Type data)
{
for (int i = 0; i < array.size(); i++)
{
if (array.get(i).contains(data))
{
return true;
}
}
return false;
}
public int getNumRows()
{
return array.size();
}
public int getNumCols(int row)
{
return array.get(row).size();
}
}