---
tags: [ap, ap/csa, notes, code]
---
# AP CSA Unit 7 Notes
- **Unit 7**
- ArrayList
- ArrayList is resizeable
- ArrayList is designed for reference type objects, not primitive types
- but we can use wrapper classes to have them
- we declare an ArrayList differently to the way we would an array
- `ArrayList<Type> = new ArrayList<Type>();`
- we can populate it with the `.add(object)` method, which just adds it
at the end, or the `.add(index, object)` to specify where to add it
- when using the second method, the elements are pushed along one
index to make space for the new element
- the first method always returns `true`, but the second one is
void
- we can replace an element using the `.set(index, object)` method
which returns the element that was previously there
- we can remove an element using the `.remove(index)` method, which
just sets back every other element one index, deleting the specified one and
returns the removed element
- we can get an element with the `.get(index)` method
- we can get the size of the ArrayList object by using the `.size()`
method