关于迭代器remove的问题

ttigerdna 2018-02-10 05:21:44
代码


Iterator<CropsCycleForecast> cropsCycleForecastIt=cropsCycleForecastList.iterator();
while(cropsCycleForecastIt.hasNext()){
CropsCycleForecast cropsCycleForecastz=cropsCycleForecastIt.next();
if(cycle_type.equals(cropsCycleForecastz.getCycleType())){
cropsCycleForecastIt.remove();
continue;
}
}


遍历中 删除元素 还需要加continue吗?
...全文
901 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
continue基本是需要结合一些逻辑IF判断时使用,你这样用,基本没有啥意义!
  • 打赏
  • 举报
回复
不需要的,continue是跳出当前循环,执行下次循环,一般用做逻辑判断跳出当前循环
appleyk 2018-02-11
  • 打赏
  • 举报
回复
不需要啊,你那continue只是在删除元素的时候,当前循环跳出,不在向下执行


ttigerdna 2018-02-10
  • 打赏
  • 举报
回复


Iterator<CropsCycleForecast> cropsCycleForecastIt=cropsCycleForecastList.iterator();
        while(cropsCycleForecastIt.hasNext()){
                CropsCycleForecast cropsCycleForecastz=cropsCycleForecastIt.next();
                         if(cycle_type.equals(cropsCycleForecastz.getCycleType())){
                             cropsCycleForecastIt.remove();
                             continue;
                       }
                      Area area=cropsCycleForecastz.getArea();
			System.out.println("area id:"+area.getId());
			Station stationSerach=new Station();
                        ...
            }

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧