我从例如代码,但它不工作:迭代器remove方法
List<Byte> myList = Arrays.asList(B);
Iterator<Byte> itr = myList.iterator();
while(itr.hasNext())
{
Byte element = itr.next();
if(element == 32)
{
itr.remove();
}
}
我无法理解为什么上面的代码生成以下异常。
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:144)
at java.util.AbstractList$Itr.remove(AbstractList.java:360)
因为这正是文档说它会做的? –