VOOZH about

URL: https://www.geeksforgeeks.org/java/arrays-aslist-method-in-java-with-examples/

⇱ Arrays asList() Method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Arrays asList() Method in Java with Examples

Last Updated : 14 Apr, 2026

The Arrays.asList() method in Java is part of the java.util.Arrays class, which is used to convert an array into a fixed-size list. 

  • Mainly used to get a List view a given array.
  • Note that the list returned and the original array share the same memory. It only gives a list. As we can see in the below program, a change made in the array also reflects in the list.
  • Acts as a bridge between array-based and collection-based APIs, in combination with Collection.toArray() which does the opposite.

Output
[1, 2, 3, 4, 5]
20

Syntax

public static <T> List<T> asList(T... a)

Parameters:

  • "T... a" is an array of elements to be converted into a List.
  • The "..." indicates that this is a varargs parameter and it allows multiple elements of type T to be passed as an array.

Return Value:List<T>: This method returns a fixed-size list that contains elements of the same type as the array elements.

Examples of Using the asList() Method in Java

Example: Using asList() Method with String Array


Output
[A, B, C, D]

Example: Using asList() Method with Integer Array


Output
[10, 20, 30, 40]

Example: UnsupportedOperationException with asList()


Output
Exception thrown: java.lang.UnsupportedOperationException

Note: The code compiles successfully, but modifying the list (using add() or remove()) throws a UnsupportedOperationException at runtime because the list is fixed-size

Output:

👁 Output
Comment
Article Tags: