Array List Pepper
Why not just primitive arrays Inserting is awkward Everything must shift Removal is awkward Common tasks Print an array Contains Index of Last Index Of Get size
Syntax Generic Class Class definition takes in a type parameter ArrayList<E> E is the type ArrayList<String> is "array list of type string" ArrayList<String> var = new ArrayList<String>() ArrayList<Player> var = new ArrayList<Player>() Think of the classname as ArrayList<Player> Also legal: ArrayList<String> var = new ArrayList<>() Call methods like any object: var.add("A value");
Add
Remove
Contains
Methods Write a method to add an element with "~" between every existing element
Looping issues The indexes and size keep changing
Insert ~ before each element Problem:
Insert ~ before each element Good
Removing every other Problem
Removing every other Good
Searching Write a replace method
Replace
Wrapper No primitives Wrap up into an Integer class AutoBoxing sometimes Equals problem
Summary Create an ArrayList: Use arraylist methods Wrap an integer ArrayList<String> v = new ArrayList<String>(); Use arraylist methods Understand size and indexes change with methods Wrap an integer