Presentation is loading. Please wait.

Presentation is loading. Please wait.

Array List Pepper.

Similar presentations


Presentation on theme: "Array List Pepper."— Presentation transcript:

1 Array List Pepper

2 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

3 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");

4 Add

5 Remove

6 Contains

7 Methods Write a method to add an element with "~" between every existing element

8 Looping issues The indexes and size keep changing

9 Insert ~ before each element
Problem:

10 Insert ~ before each element
Good

11 Removing every other Problem

12 Removing every other Good

13 Searching Write a replace method

14 Replace

15 Wrapper No primitives Wrap up into an Integer class
AutoBoxing sometimes Equals problem

16 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


Download ppt "Array List Pepper."

Similar presentations


Ads by Google