In this example we will show how to create a List from an array of type Object with asList method of Arrays class.
Source Code
package com.beginner.examples;
import java.util.Arrays;
import java.util.List;
public class ArrayToListExample {
public static void main(String[] args) {
String[] str ={"A","B","C","D","E"};
//Use the asList() method of the Arrays utility class to convert those Arrays
List strList = Arrays.asList(str);
System.out.println(strList);
}
}
Output:
[A, B, C, D, E]
References
Imported packages in Java documentation: