ArrayLists practice

posted by: Ms. Martin 7 February 2011 No Comment

Do these practice problems to familiarize yourself with ArrayLists.  The trickiest thing about them is keeping track of how the size changes as you add and remove values.  Keep in mind that if you remove a value, the next value in the list now has the same index as the one you removed!  I find it useful to think of these in terms of while loops.

Don’t forget that these are static methods!  We’ll come back to instance methods with our next project which will require you to use an ArrayList as a component of a larger class.



markLengthFour — beware of infinite loops… what happens to your indexes when you add a value?

removeBadPairs — this one will require very careful thinking about how indexes change as you remove elements…

1 Star2 Stars3 Stars4 Stars5 Stars (11 votes, average: 2.91 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>