【发布时间】:2021-03-27 06:18:42
【问题描述】:
这是一个代码 sn-p 移动到链表中的下一个元素。在调试时,itrPlaylist.next() 正在触发 ConcurrentModificationException。我读到在迭代时不应修改列表。那么,在这种情况下,我哪里做错了?怎么解决?
提前致谢。
public boolean nexxt() {
if(this.itrPlaylist.hasNext())
{
if(!bForward)
{
bForward = true;
itrPlaylist.next();
}
System.out.println("Now playing : " + itrPlaylist.next());
return true;
}
else
{
System.out.println("Reached end of " + this.getPlaylistName() + " playlist !");
}
return false;
}
【问题讨论】:
-
首先要调用 next() 两次