G
George
Hi,
I need to do a breadth-first search on a graph. So I need to have a
list for element and iterator over it while keep adding element in the
end of the list. I am currently using ArrayList in java 5. I
remembered vaguely something about the iterator is unpredictable when
the collection changed. Is it true?
Can I use
List<E> list=new ArrayList<E>;
......
for (ListIterator<E> it = list.listIterator(); it.hasNext(); )
{....; list.add(x);
}
or can I use
for (x:list){
.....; list.add(x);
}
I need to do a breadth-first search on a graph. So I need to have a
list for element and iterator over it while keep adding element in the
end of the list. I am currently using ArrayList in java 5. I
remembered vaguely something about the iterator is unpredictable when
the collection changed. Is it true?
Can I use
List<E> list=new ArrayList<E>;
......
for (ListIterator<E> it = list.listIterator(); it.hasNext(); )
{....; list.add(x);
}
or can I use
for (x:list){
.....; list.add(x);
}