How do arrays and ArrayList differ? When should you use a plain array?
Short answer
An array has a fixed size and can hold int. An ArrayList grows by itself but holds objects only, so numbers get boxed (wrapped into Integer).
3 points to say:
- Array: fixed size, compact in memory.
ArrayList: grows by itself, numbers get boxed.- Default to
ArrayList; for lots of numbers use an array.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.