previous | start | next

## The `ArrayList` class

- Collects objects of any class type
- `add` appends to the end

      ArrayList countries = new ArrayList();

      countries.add("Belgium");

      countries.add("Italy");

      countries.add("Thailand");

- `size` method yields number of elements
  `for (int i = 0; i < countries.size(); i++) . . .`
- `get` gets an element; must cast to correct type:
  `String country = (String)countries.get(i);`
- `set` sets an element
  `countries.set(1, "France");``
  `

previous | start | next