This is how I did it:
- Start off with a single ArrayList of size 0 that contains nothing.
- When you add a Vertex, add a new ArrayList to the outer ArrayList
and increment a static counter (one that will, from here on it, keep
track of the number of vertices)
- Fill in the inner ArrayList(s) from 0 to the counter with null
values
- Rinse and repeat (adding a null value to each of the previous
ArrayLists every time you add a new ArrayList to the outer ArrayList)
As for your other problem, I'm not entirely sure what you mean, but
ArrayLists have the method set(index, element) where you can put a
value into any index of the ArrayList that you wish.