Java数组第一次remove对象抛出异常

来源:互联网 发布:微通话软件下载 编辑:程序博客网 时间:2024/05/17 05:08

使用正常的for 循环移除对象:

List<UserInfo > std1 = new ArrayList<UserInfo >();        for (UserInfo stds : std1) {              std1.remove(stds);//循环移除数据modCount 错误         }

使用迭代器移除对象:

for (Iterator iterator = std1.iterator(); iterator.hasNext();) {  UserInfo ui= (UserInfo)iterator.next();            iterator.remove();//移除的是取到的ui值 }

想要删除不能用增强的for循环,否则会出现concurrentmodificationexception,建议用Iterator,然后用Iterator.remove();

2 0
原创粉丝点击