Contents
Page-10
Prev
Next
Page+10
Index
ArrayList
ArrayList provides a growable array implementation of a List.
Advantages:
- get and set are O(1)
- add and remove at the end are O(1), so an
ArrayList makes a good implementation of a stack.
Disadvantages:
- add and remove are O(n) for random positions:
the rest of the list has to be moved down to make room.
- contains is O(n). contains uses the .equals()
method of the contents type.
- Some space in the array is wasted, O(n), because the array grows
by a factor of 3/2 each time it is expanded.
- clear is O(n), because clear replaces all existing
entries with null to allow those items to possibly be garbage collected.