Java Arrays.asList() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.util.Arrays

Definition

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
CallWhat 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

ParameterDescription
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 ValueDescription
List<T>A fixed-size, serializable list view of a that supports get, set, size, contains, indexOf, iteration, and sorting.

Compare with Similar Methods

Ways to get a List from an array:

MethodHow it differs
new ArrayList<>(Arrays.asList(a))An independent copy that supports add and remove.
List.of(...) (Java 9)Fully unmodifiable: even set fails, and null elements are rejected.
Arrays.stream(a)Needed for primitive arrays: Arrays.stream(ints).boxed() collects into a List<Integer>.
list.toArray(...)The opposite direction: from a list back to an array.

Java Examples

Example 1 — Changes Flow Both Ways

Wrap an array in a list, change an element through the list, then change the array directly.

Java
import java.util.Arrays;
import java.util.List;

public class ArraysAsListDemo {
    public static void main(String[] args) {
        String[] colors = {"red", "green", "blue"};
        List<String> list = Arrays.asList(colors);

        System.out.println("list: " + list + ", size " + list.size());
        list.set(1, "lime");
        System.out.println("array after set: " + Arrays.toString(colors));

        colors[2] = "navy";
        System.out.println("list after array change: " + list);
    }
}

How It Works

  1. No copy is made. Arrays.asList(colors) returns a small wrapper that reads and writes the colors array itself.
  2. List to array. list.set(1, "lime") stores the new value in colors[1], which the array print confirms.
  3. Array to list. Assigning colors[2] = "navy" changes what the list reports at index 2.
  4. Size never moves. The list size is the array length, 3, and stays that way whatever you set.

Example 2 — add() Fails, a Copy Works

Try to add to the fixed-size list, then copy it into an ArrayList that can grow.

Java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArraysAsListFixedSize {
    public static void main(String[] args) {
        List<String> fixed = Arrays.asList("Ann", "Ben");
        try {
            fixed.add("Cy");
        } catch (UnsupportedOperationException e) {
            System.out.println("add failed: the list has a fixed size");
        }

        List<String> growable = new ArrayList<>(fixed);
        growable.add("Cy");
        growable.remove("Ann");
        System.out.println("fixed:    " + fixed);
        System.out.println("growable: " + growable);
    }
}

How It Works

  1. Varargs input. Arrays.asList("Ann", "Ben") creates a two-element array behind the scenes and wraps it.
  2. Growing is not allowed. add("Cy") would need a longer array, so the list throws UnsupportedOperationException and the catch block prints a message.
  3. Independent copy. new ArrayList<>(fixed) copies both names into a real ArrayList, where add and remove work.
  4. The original is untouched. Adding Cy and removing Ann only affected growable; fixed still prints [Ann, Ben].

Example 3 — Why Arrays.asList(int[]) Gives One Element

Compare an int[] with an Integer[] holding the same numbers.

Java
import java.util.Arrays;
import java.util.List;

public class ArraysAsListPrimitives {
    public static void main(String[] args) {
        int[] raw = {4, 5, 6};
        List<int[]> wrong = Arrays.asList(raw);
        System.out.println("int[] -> list size " + wrong.size());

        Integer[] boxed = {4, 5, 6};
        List<Integer> right = Arrays.asList(boxed);
        System.out.println("Integer[] -> " + right + ", size " + right.size());
        System.out.println("contains 5? " + right.contains(5));
    }
}

How It Works

  1. Generics need objects. T cannot be int, so for an int[] Java picks T = int[] and treats the whole array as one value.
  2. One element. The result is a List<int[]> whose single element is the array, so its size is 1, not 3.
  3. Wrapper array works. Integer[] is an array of objects, so T = Integer and each number becomes its own list element.
  4. 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.

Next: Arrays.binarySearch()

Find a value in a sorted array quickly, or where it would go.

binarySearch() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful