In Java, Arrays.asList(a) returns a List that is a view of the array a. Nothing is copied: reading the list reads the array, set on the list writes into the array, and changes to the array show up in the list.
Because the array cannot change its length, the list has a fixed size. add, remove, and clear throw UnsupportedOperationException. The returned object is a private class inside Arrays, not a java.util.ArrayList; wrap it in new ArrayList<>(...) when you need a list that can grow.
A static method of java.util.Arrays (Java 1.2+): call it on the class, as in Arrays.asList(...); there is no Arrays object to create. It takes varargs (since Java 5), so you can pass an existing array or a comma-separated list of values.
Syntax
Pass an object array or individual values.
Java
List<String> a = Arrays.asList("x", "y", "z"); // [x, y, z]
String[] arr = {"p", "q"};
List<String> view = Arrays.asList(arr); // backed by arr
List<String> copy = new ArrayList<>(Arrays.asList(arr)); // independent, growable
Call
What it does
Arrays.asList(v1, v2, v3)
Quick fixed-size list from literal values.
Arrays.asList(array)
List view over an existing object array.
new ArrayList<>(Arrays.asList(array))
Copies the elements into a list that can grow and shrink.
list.set(i, value)
Allowed: replaces an element and writes it into the array.
asList works on object arrays. For an int[], the whole array becomes a single element, giving a List<int[]> of size 1. Use Integer[], or Arrays.stream(ints).boxed(), to get a List<Integer>.
Library declarations
Java
// java.util.Arrays (since Java 1.2; varargs since Java 5)
@SafeVarargs
public static <T> List<T> asList(T... a)
Parameters
Parameter
Description
a (T...)
The array that backs the list, or the values to put in it. The array itself must not be null; its elements may be null.
Return Value
Return Value
Description
List<T>
A fixed-size, serializable list view of a that supports get, set, size, contains, indexOf, iteration, and sorting.
Generics need objects.T cannot be int, so for an int[] Java picks T = int[] and treats the whole array as one value.
One element. The result is a List<int[]> whose single element is the array, so its size is 1, not 3.
Wrapper array works.Integer[] is an array of objects, so T = Integer and each number becomes its own list element.
Searching boxes the key.right.contains(5) turns 5 into an Integer and finds it with equals.
Frequently Asked Questions
No. It has a fixed size, so add, remove, and clear throw UnsupportedOperationException. Copy it with new ArrayList<>(Arrays.asList(...)) to get a list that can grow.
No. The list is a view of the array: set() on the list writes into the array, and changing the array changes the list.
Generics cannot use primitive types, so the whole int[] becomes one element of a List<int[]>. Use an Integer[] or Arrays.stream(intArray).boxed().
No. It is a private nested class inside Arrays that happens to be named ArrayList. It implements List but cannot change size.
List.of (Java 9) is fully unmodifiable and rejects null elements. Arrays.asList allows set() and null elements and is backed by the array.