JAVA array to list and list to array

    //convert array to list
    Integer[] arr = new Integer[]{1, 2};
    /*
    fixedSizeList Arrays.ArrayList的一个实例,定长,不能新加元素。
    fixedSizeList.add(3) 会抛出 UnsupportedOperationException
     */
    List<Integer> fixedSizeList = Arrays.asList(arr);
    List convertedList = new ArrayList<>(fixedSizeList);

    //convert list to array
    List<Integer> list = new ArrayList<>();
    list.add(1);
    list.add(2);
    /*
    list.toArray()得到是一个Object[]
    list.toArray(T[] a)得到一个T[]
     */
    Integer[] convertedArr = list.toArray(new Integer[0]);
原文地址:https://www.cnblogs.com/cnsec/p/13547571.html