Arrays.asList in Java

The java.util.Arrays.asList returns a fixed-size list that is​ backed by the specified array; the returned list is serializable and allows random access.

Syntax

The function declaration of the Arrays.asList():

svg viewer

Code

The code snippet below illustrates the usage of the asList() function:

import java.util.Arrays;
import java.util.List;
class AsList_Demo {
public static void main (String args[]) {
// create an array of strings
String fruits[] = new String[]{"Apple","Mango","Kiwi","Banana"};
List l = Arrays.asList(fruits);
// output list
System.out.println("Fruits: " + l);
}
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved