Java将阵列更改为列表


Java将阵列更改为列表

import java.util.ArrayList;

import java.util.List;



public class ArrayToArrayList {

   public static void main(String args[]) {

      int[] myArray = {20, 30, 45, 58, 96};

      List<Integer> list = new ArrayList();

      for (int i=0; i<myArray.length; i++) {

         list.add(myArray[i]);

      }

      System.out.println("Contents of the list ::"+list);

   }

}