我试过下面的代码
String s[]={"1","2","3","4"}; Collection c=Arrays.asList(s); System.out.println(c.remove("1") +" remove flag"); System.out.println(" collcetion "+c);
我正在
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:26)
谁能帮我解决这个问题?
简单的解决方法是将List传递到ArrayList的构造函数中。
ArrayList
例如:
字符串valuesInArray [] = {“ 1”,“ 2”,“ 3”,“ 4”}; 列表modifiableList = new ArrayList(Arrays.asList(valuesInArray)); System.out.println(modifiableList.remove(“ 1”)+“ remove flag”); System.out.println(“ collcetion” + modifiableList);
响应:
真删除标志 集合[2,3,4]
真删除标志
集合[2,3,4]