Java Collection Tutorial - Java Arrays.asList(T... a)


Arrays.asList(T... a) has the following syntax.

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


In the following code shows how to use Arrays.asList(T... a) method.

//w w w.  jav a2s.  co  m
import java.util.Arrays;
import java.util.List;

public class Main {
  public static void main (String args[]) {

   // create an array of strings
   String a[] = new String[]{"CSS","HTML","Python","tutorial from"};
   List<String> list1 = Arrays.asList(a);

   // printing the list
   System.out.println("The list is:" + list1);

The code above generates the following result.