3
可能重複時:
Why I get UnsupportedOperationException when trying to remove from the List?java.lang.UnsupportedOperationException調用List.remove(指數)
當我打電話List.remove(指數)或list.remove(元件)它會引發java.lang.UnsupportedOperationException。唯一培訓相關的錯誤代碼是這樣的:
17:08:10 [SEVERE] at java.util.AbstractList.remove(Unknown Source)
下面是一個例子:
String line = "cmd /say This is a test";
String[] segments = line.split(" ");
String cmd = segments[0];
List rest = Arrays.asList(segments);
rest.remove(0); // This line raises the exception
沒有人有任何想法,爲什麼發生這種情況?在我的執行代碼中,我檢查了索引爲0的元素並將其刪除。