Converting array to list in Java
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Converting an array to a list in Java is easy, but the details matter because not all resulting lists behave the same way. Some conversions produce a fixed-size view backed by the original array, while others produce a fully mutable list copy.
The right approach depends on what you need next: read-only access, mutation, stream processing, or support for primitive arrays.
Arrays.asList for the Basic Case
The classic conversion is Arrays.asList(array).
This is concise and efficient, but the result has an important limitation: it is fixed in size.
You can replace an element with set, but you cannot add or remove elements.
It is also backed by the original array, which means updates can be reflected both ways.
Make a Fully Mutable List Copy
If you need to add or remove elements, wrap the result in an ArrayList.
This is the most common conversion when the list will be edited after creation.
Stream-Based Conversion
Streams are useful when you want to transform values while converting.
That is more verbose than Arrays.asList, but it is better when conversion and transformation belong together.
Primitive Arrays Are Different
A very common trap is expecting Arrays.asList to work the same way for int[] or double[].
That produces a list with one element: the entire primitive array.
For primitive arrays, use streams and boxing.
This is the correct way to get List<Integer> from int[].
Modern Read-Only Alternatives
If you want an unmodifiable list from values you already know, List.of(...) is often cleaner than array conversion, though it starts from individual elements rather than from an existing array.
If you already have an array and want an immutable snapshot, use:
That creates an unmodifiable list independent of later structural changes.
Common Pitfalls
The biggest mistake is assuming Arrays.asList returns a normal fully mutable ArrayList. It does not.
Another common issue is forgetting that the returned list is backed by the original array. Mutating one can affect the other.
Primitive arrays are another frequent source of confusion. Arrays.asList(intArray) does not give you List<Integer>.
Finally, use streams when you genuinely need transformation logic, not just because streams exist. For simple object-array conversion, Arrays.asList or new ArrayList<>(...) is usually clearer.
Summary
- '
Arrays.asList(array)is the standard object-array to list conversion.' - The result is fixed-size and backed by the original array.
- Wrap it in
new ArrayList<>(...)if you need a mutable list. - Use streams when you want to transform elements during conversion.
- Primitive arrays need boxing, not plain
Arrays.asList. - Choose the conversion style based on mutability and data type.

