# Lecture 11 (Edwards) - ArrayLists and 2D Arrays

Lecture Date: Wednesday, February 18

Let’s look at the specific differences between Arrays and ArrayLists:

Array ArrayList Meaning
`int[]` `ArrayList<Integer>` type of a list of integer
`new int` (not doable) create a list that can hold 3 things
(not doable) `new ArrayList<Integer>()` create an empty list that can grow later
`int[] a = {1, 2, 3};` (write a loop) create a list with the given values inside
`a = 5` `a.set(2, 5)` sets the 3rd elements of the list to be value 5
`x = a` `x = a.get(2)` retrieves the 3rd element of the list
`a.length` `a.size()` the number of elements in the list
(write a loop) `a.toString()` a pretty textual representation of the list
(not doable) `a.add(1110)` adds a new element to the end of the list, making the list 1 element longer than it was
(not doable) `a.remove(2)` removes the element that was at index 2
(not doable) `a.remove(new Integer(2))` removes the first 2 from the list (if there is a 2 in the list)

We will also discuss 2D Arrays and how they are really arrays of arrays.

Code: