Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

arrays
aslist
java

Arrays.asList in Java

Educative Answers Team

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);
   }
}

RELATED TAGS

arrays
aslist
java
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring