Do you know how to iterate over the elements of an ArrayList and how to get elements from an ArrayList? Once you know this, it should be pretty straightforward to do what you want. Have a look at the
Collections tutorial to learn how to work with collection classes such as ArrayList.
By the way, your code is a bit verbose. This works just as well: