Java.util.Arrays.asList() Method
Advertisements
Description
The java.util.Arrays.asList(T... a) returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs,
Declaration
Following is the declaration for java.util.Arrays.asList() method
public static <T> List<T> asList(T... a)
Parameters
a -- This is the array by which the list will be backed.
Return Value
This method returns a list view of the specified array.
Exception
NA
Example
The following example shows the usage of java.util.Arrays.asList() method.
package com.tutorialspoint;
import java.util.Arrays;
import java.util.List;
public class ArrayDemo1 {
public static void main (String args[]) {
// create an array of strings
String a[] = new String[]{"abc","klm","xyz","pqr"};
List list1 = Arrays.asList(a);
// printing the list
System.out.println("The list is:" + list1);
}
}
Let us compile and run the above program, this will produce the following result:
The list is:[abc, klm, xyz, pqr]