Collections: Arrays.asList is fixed-size

Arrays.asList wraps the array, so set works but add and remove do not. Wrap it in a new ArrayList when you need a growable list.

Code
var fixed = Arrays.asList("a", "b", "c");
fixed.set(0, "z");
System.out.println("set works: " + fixed);

try {
    fixed.add("d");
} catch (UnsupportedOperationException e) {
    System.out.println("add fails - the list is fixed-size");
}

var growable = new ArrayList<>(Arrays.asList("a", "b"));
growable.add("c");
System.out.println("wrapped in ArrayList: " + growable);
Output
set works: [z, b, c]
add fails - the list is fixed-size
wrapped in ArrayList: [a, b, c]
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-07-30