Array to List Java

After knowing how to convert list to array, let us do the other way array to list java.

To convert list to array we used to toArray() method. Now the method to convert array to list Java is asList() method of class Arrays (do not confuse, there is class called Arrays in Java from java.util package).

Following is the example on Array to List Java
import java.util.*;
public class ArrayToList
  public static void main(String args[])
    String employeeArray[] = { "Jyothi", "Sridhar", "Jyostna", "Srinivas", "Sumathi" };
    List employeeList = Arrays.asList(employeeArray);


Array to List JavaOutput Screenshot on Array to List Java

asList() method of Arrays class returns an object List employeeList with the elements of the array employeeArray. But the list employeeList is immutable. That is you cannot delete or add one more element to employeeList. Adding an element throws java.lang.UnsupportedOperationException.

class Arrays is a boon to Developers to manipulate array elements otherwise which takes lengthy codes to write your own code as you did in C/C++. All the methods are discussed with examples and screenshots in Java class Arrays.

Leave a Comment

Your email address will not be published.