How to create an ArrayList from an Array in Java?

Java 8Object Oriented ProgrammingProgramming

The asList() method is used to convert an array to list.

Example:

import java.util.Arrays;
import java.util.List;

public class ArrayToList {
   public static void main(String args[]){
      Integer[] myArray = {23, 93, 56, 92, 39};
      List list = Arrays.asList(myArray);
      System.out.println(list);
   }
}

Output:

[23, 93, 56, 92, 39]
raja
Published on 17-Jan-2018 10:13:22
Advertisements