October 2014
Beginner to intermediate
285 pages
6h 24m
English
An ArrayList in Java also keeps track of a list of values, just like a simple Array does. ArrayLists are a little messy to declare but simple enough to use, and much more flexible and a bit safer than plain old Array objects. You can add and delete from the ArrayList as many times as you want; it’s not a fixed length and will grow or shrink as needed.
Here’s an example of an ArrayList that will hold Player objects:
| | List<Player> myPlayerList = new ArrayList<Player>(); |
There’s a lot more gunk in there than we’ve seen up to now. First of all, I’ve called our new list myPlayerList. Note that funny syntax with the angle brackets, < and >. You have to specify the kind of list you’re making (twice, in fact). Java 7 improves ...
Read now
Unlock full access