Create ArrayList from array
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Java, the usual way to create an ArrayList from an array is to wrap the array with Arrays.asList and then pass that list into the ArrayList constructor. The important nuance is that Arrays.asList alone does not give you a fully normal resizable ArrayList; it gives you a fixed-size list backed by the original array.
The Common Resizable Pattern
If you want a real ArrayList, write:
This is the standard idiom because it copies the elements into a new resizable list.
Know What Arrays.asList Actually Returns
Arrays.asList(array) is often misunderstood. It returns a fixed-size list view backed by the original array.
That works because element replacement is allowed, but add and remove are not.
That throws UnsupportedOperationException.
So if you need a mutable list structure, wrap it in new ArrayList<>(...).
Collections.addAll Is Also Fine
Another readable option is to create the list first and then add the array contents.
This is especially convenient when you are already constructing the list in several steps.
Primitive Arrays Need Special Attention
A classic trap is using Arrays.asList with a primitive array.
That produces a list with one element, the entire int[], not a list of boxed integers.
For primitive arrays, convert explicitly.
Choose Mutable or Immutable Intentionally
Sometimes you do not need an ArrayList specifically. If the goal is simply “turn this array into a list,” the bigger design choice is whether the result should be mutable.
If later code will add or remove elements, create a real ArrayList. If the result should stay fixed, another list form may express the contract more clearly.
That is often more important than the exact conversion syntax.
Copying Also Breaks Array Coupling
A new ArrayList is not just about resizability. It also breaks the direct backing relationship to the original array. That can matter if later code mutates either structure and you do not want those changes reflected in the other.
Common Pitfalls
- Assuming
Arrays.asListreturns a normal resizableArrayList. - Calling
addorremoveon the list returned directly byArrays.asList. - Forgetting that
Arrays.asListwith a primitive array creates a one-element list. - Mutating a list view backed by the array without realizing changes can reflect into the original array.
- Choosing a conversion style without thinking about whether the result should be mutable.
Summary
- Use
new ArrayList<>(Arrays.asList(array))for the standard resizable result. - '
Arrays.asListalone gives a fixed-size list backed by the array.' - '
Collections.addAllis a clear alternative when building the list manually.' - Primitive arrays need explicit boxing if you want a list of values.
- Choose the conversion based on mutability needs, not just syntax convenience.

