I have a 2D ArrayList
List<List<String>> transitionTable = new ArrayList<List<String>>()
If I'm correct, adding "rows" to this would be (correct me if I'm wrong)
transitionTable.add(new ArrayList<String>())
How would I go about adding the equivalent of a column? Use a for loop something like this?:
for (int i = 0; i < transitionTable.get(0).size(); i++)
{
transitionTable.get(i).add("something");
}
edit: Now having trouble figuring out why it stops adding after a certain point, it's always at index i = anything (depending on how many times I've iterated the loop" j = 1 (always)
I forgot to mention I'm aiming for a nxn 2d arraylist (a square basically)
This is my code so far:
transitionTable.add(new ArrayList<String>()); //Adds a new row
if (transitionTable.size() == 1)
{
transitionTable.get(0).add("NULL"); //Adds a new column.
}
else
{
for (int i = 0; i < transitionTable.get(0).size(); i++)
{
transitionTable.get(i).add("NULL"); //Adds a new column (needs to iterate for each row to create something like a column)
}
}