0% found this document useful (0 votes)
86 views1 page

AP CSA Unit 7: ArrayList Guide

The document discusses ArrayList in Java, including that it is resizeable and designed for reference types. It notes how to declare, populate, replace elements in, remove elements from, get elements from, and get the size of an ArrayList.

Uploaded by

Ulysse Berra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views1 page

AP CSA Unit 7: ArrayList Guide

The document discusses ArrayList in Java, including that it is resizeable and designed for reference types. It notes how to declare, populate, replace elements in, remove elements from, get elements from, and get the size of an ArrayList.

Uploaded by

Ulysse Berra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

---

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

You might also like