解决Collection was modified; enumeration operation may not execute异常

今天在使用foreach循环遍历list集合时,出现Collection was modified; enumeration operation may not execute.这个错误,查了半天才发现是当想要修改list集合时,不能使用foreach,因为foreach是取只读的,在取的时候数据不能变(包括修改,删除,添加等),所以只能用for循环。

posted @ 2013-09-23 14:46  海之缘  阅读(12363)  评论(1编辑  收藏  举报
如果你真的想做一件事,你一定会找到方法; 如果你不想做一件事,你一定会找到借口