name: inverse layout: true class: taylor msoe --- class: center, middle .title[ # ArrayList ] ??? Toggle speaker view by pressing P Pressing C clones the slideshow view, which is the view to put on the projector if you're using speaker view. Press ? to toggle keyboard commands help. --- # Wrapping an Array in a Class * Give behaviors to an array -- * Simplify managing lists of data -- * Hide subscript operator behind methods ??? --- # Declaring and Instantiating `ArrayList`s * Make use of a generic type for flexibility -- * Specify type to be stored in the list as a generic: `ArrayList
words;` -- * Generic type must be a reference type (cannot be a primitive) -- * Instantiate ArrayList similar to other objects: `words = new ArrayList<>();` --- # Popular Methods * `size()`/`isEmpty()`/`clear()` -- * `get(int)`/`set(int, E)` -- * `add(E)`/`remove(Object)`/`contains(Object)` -- * `add(int, E)`/`remove(int)`/`indexOf(Object)`/`lastIndexOf(Object)` -- * `toArray()` --- class: animated slideInUp, middle # ArrayList Internals ``` java List
list = new ArrayList<>(); list.add("dog"); list.add(null); list.add("pig"); list.add("cat"); list.add("cow"); list.add(null); ```