我尝试了下面的代码,它仅适用于 1 个数组,当我尝试添加另一个数组时,它会引发运行时异常
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.add(Unknown Source)
at java.util.AbstractList.add(Unknown Source)
at general.ArrToArrList.main(ArrToArrList.java:32)
代码是
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
public class ArrToArrList {
public static void main(String[] args) {
Integer[] nums = new Integer[5];
nums[0] = 2;
nums[1] = 4;
Integer[] nm = { 3, 5, 7 };
List intList = (Arrays.asList(nums));
List intList2 = (Arrays.asList(nm));
intList.addAll(Arrays.asList(nm));
for (Integer i : intList) {
System.out.println(i);
}
}
}