出错写法:
while(list.iterator.hasNext()){
object item = iterator.next();
}
原因:每次调用iterator的时候ArrayList返回的总是一个new ListItr,这样每次拿到的结果都是第一个对象
public ListIterator<E> listIterator(int index) {
if (index < 0 || index > size)
throw new IndexOutOfBoundsException("Index: "+index);
return new ListItr(index);
}
纠正写法:
Iterator<Object> iterator = list.iterator();
while(iterator.hasNext()){
Object object = iterator.next();
}