How to copy an iterator to another one?

后端 未结 3 1083
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 18:39

I need to iterate over the set of values for each iteration of for loop, but only for first iteration it works fine. Thereafter the itr.hasNext() returns

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 19:10

    It depends on the exact contents of your code block, but why not flip the loops? Have the outer loop go over the file, and for each iteration, go over all the Persons:

    Iterator itr = getQuestionIterator(File file);
    while(itr.hasNext()) 
    {
        String question = itr.next();
        for(Person p : persons)
        {    
            ........
            ........
        }
    }
    

提交回复
热议问题