previous |
start |
next
Retrieving Array List Elements
- Use get method
- Index starts at 0
- Must cast to correct type
- Coin c = coins.get(0); // gets first coin
- Bounds error if index is out of range
- Most common bounds error:
int n = coins.size();
c = (Coin)coins.get(n); // ERROR
// legal index values are 0...n-1
previous |
start |
next