在foreach調用remove可能會引發ConcurrentModificationException。
如:
for(Object obj : list){
.remove(obj);
}
最好像下面這樣寫:
for (Iterator it = list.iterator(); it.hasNext();) {
......
it.remove();
}
(添加20160420)
如果foreach的同時需要add element,就不能使用iterator了,最好重新啟用一個新的list暫存新的集合元素。