Robert Harp wrote:I need help converting my code into an ArrayList. We are only supposed to use an ArrayList and not an array. I didn't see that part of my project and not too good with using ArrayList. Please help me figure this out.
It's fairly straightforward:
Every place you have 'X[]', replace it with 'List<X>' (note: much better than 'ArrayList<X>').Every place you have 'new X[n]', replace it with 'new ArrayList<X>(n)'.Every place you have 'arrayname[n]' that is not followed by an '=' sign, replace it with 'listname,get(n)'.
The only other thing to deal with is initializing its values, and the easiest way to do that is to add them in the order you want. Have a look at the API docs for
ArrayList.add() for details.
HIH
Winston