任何人都可以幫我解決問題嗎?刪除Enum列表問題
public static void main(String[] args)
{
List<TestEnum> list1 = new ArrayList<TestEnum>();
list1.add(TestEnum.ONE);
list1.add(TestEnum.TWO);
list1.add(TestEnum.THREE);
System.out.println(list1);
System.out.println(list1.remove(TestEnum.TWO));
System.out.println(list1);
System.out.println("-----------------------");
TestEnum[] xx = new TestEnum[]{TestEnum.ONE, TestEnum.TWO, TestEnum.THREE};
List<TestEnum> list2 = Arrays.asList(xx);
System.out.println(list2);
System.out.println(list2.remove(TestEnum.TWO));
System.out.println(list2);
}
下面是結果 -
[ONE, TWO, THREE]
true
[ONE, THREE]
-----------------------
[ONE, TWO, THREE]
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(Unknown Source)
at java.util.AbstractList$Itr.remove(Unknown Source)
at java.util.AbstractCollection.remove(Unknown Source)
at Test.main(Test.java:24)
請幫助 - 爲什麼發生這種情況,我還檢查哈希碼?
名單()' –
的[VS新的ArrayList Arrays.asList(陣列)之間的差異可能的複製(Arrays.asList(IA) )在java](http://stackoverflow.com/questions/16748030/difference-between-arrays-aslistarray-vs-new-arraylistintegerarrays-aslist) –
jhamon