java.util.NoSuchElementException using iterator in java

我只是一个虾纸丫 提交于 2019-11-29 03:43:06

You are calling next() a bunch of times in one iteration forcing the Iterator to move to an element that doesn't exist.

Instead of

if (iterator.next().getPhonenumber() == phonenumber  && iterator.next().getType() == type && iterator.next().getDate() == date)
{
    updateLog(newLog, iterator.next().getId());
    ...

Use

Log log = iterator.next();

if (log.getPhonenumber() == phonenumber  && log.getType() == type && log.getDate() == date)
{
    updateLog(newLog, log .getId());
    ...

Every time you call Iterator#next(), it moves the underlying cursor forward.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!