Collections and Generics
ArrayList class
Which is Better, ArrayList or Array?
Is an ArrayList object preferable to an array? Not necessarily.
ArrayList | Array |
---|---|
Simple and convenient insertion method | Insertion must be programmed explicitly |
Simple and convenient deletion method | Deletion must be programmed explicitly |
Can resize itself | The size remains fixed |
Longer execution time | les execution time |
Store object references, not primitive. Storing and retrieving primitives requires autoboxing and unboxing, which takes time. | Storing primitives does not entail this cost. |
Access to element requires a method call | Access is direct |