迭代循环在另一个循环中 [英] Iteration loop inside another loop

查看:164
本文介绍了迭代循环在另一个循环中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以在另一个循环中使用Iterator吗?
我问这个是因为我找不到一种方法在第一个循环完成后再次将迭代器放在列表的开头,因此在第二个循环中iter.hasNext()会给我假

Is there any way I can use an Iterator inside another loop? I am asking this because I can't find a way to bring the iterator at the start of the list again after the first loop is done and therefore at a second loop the iter.hasNext() will give me false

Iterator iter = list.iterator();
for (int i=0;i<30;i++)
{
 while (iter.hasNext())
 {
  ...
 }

}


推荐答案

Iterator iter;
for (int i=0;i<30;i++)
{
    iter = list.iterator();
    while (iter.hasNext())
     {
      ...
     }

}

这篇关于迭代循环在另一个循环中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆