How to convert an array to a list in Java?

Java 8Object Oriented ProgrammingProgramming

The Arrays class of the java.util package provides you a method named asList(). This method accepts an array (of objects) and converts them into a list and returns it.

Example

Live Demo

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 09-Jan-2018 05:39:10
Advertisements