SteelReed

Search

Search posts, questions…

Collections & DSAQuestion 2 / 25

Junior

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).

YesNoYesNoNeed to store a sequenceMany primitivenumbers?int[] / long[]Fixed sizeor API wants an array?Plain arrayArrayList

3 points to say:

  1. Array: fixed size, compact in memory.
  2. ArrayList: grows by itself, numbers get boxed.
  3. 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.