Download presentation
Presentation is loading. Please wait.
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.