欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

java迭代器 异常_java.util.NoSuchElementException在Java中使用迭代器

发布时间:2025/3/19 35 豆豆
生活随笔 收集整理的这篇文章主要介绍了 java迭代器 异常_java.util.NoSuchElementException在Java中使用迭代器 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

我正在尝试使用迭代器遍历我的日志列表中的列表。目标是搜索包含与新日志相同的电话号码,类型和日期的日志

但是,我在条件语句中得到了java.util.NoSuchElementException。有谁知道可能导致问题的原因?

我的密码

public void addLog(String phonenumber, String type, long date, int incoming, int outgoing)

{

//Check if log exists or else create it.

Log newLog = new Log(phonenumber, type, date, incoming, outgoing);

//Log exists

Boolean notExist = false;

//Iterator loop

Iterator iterator = logs.iterator();

while (iterator.hasNext())

{

//This is where get the exception

if (iterator.next().getPhonenumber() == phonenumber && iterator.next().getType() == type && iterator.next().getDate() == date)

{

updateLog(newLog, iterator.next().getId());

}

else

{

notExist = true;

}

}

if (notExist)

{

logs.add(newLog);

}

}

总结

以上是生活随笔为你收集整理的java迭代器 异常_java.util.NoSuchElementException在Java中使用迭代器的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。