为什么在执行以下代码时出现异常。
String[] array1 = {"A","B","C","D","E"};
String[] array2 = {"F","G","H","I"};
List<String> list = Arrays.asList(array1);
list.addAll(Arrays.asList(array2)); //here getting exception
例外
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.add(Unknown Source)
at java.util.AbstractList.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at Sample6.main(Sample6.java:19)
但是这段代码运行良好。
List<String> list = new ArrayList<String>(Arrays.as.asList(array1));
list.addAll(Arrays.asList(array2));
谢谢