Java迭代器修改链表_Java恼人的迭代器不会返回链表中的元素
給出以下代碼:
public void insertIntoQueue(float length,int xElement,int yElement,int whichElement)
{
Dot dot = new Dot(xElement,yElement);
GeometricElement element = null;
// some code
int robotX,robotY;
boolean flag = false;
for (Iterator i = robotList.iterator(); i.hasNext();)
{
// Robot currentRobot = (Robot) i.next();
robotX = ((Robot)(i)).getXlocation();
robotY = ((Robot)(i)).getYlocation();
// more code , irrelevant
}我有以下對象:Robot,GeometricElement和Dot。
我想在一個Robot鏈接列表上進行迭代,其定義如下:
public class Ground {
// more fields
private LinkedList robotList; // used for storing the robots
public Ground(int row,int col) // ctor
{
// some code
this.robotList = new LinkedList();
}
}但行:robotX = ((Robot)(i)).getXlocation();
和robotY = ((Robot)(i)).getYlocation();
拋出dispatchUncaughtException的異常。
請注意,我不想從鏈接列表中刪除元素,
我需要的是從迭代器中獲取當前元素的字段。
那么,怎么了?
問候
羅恩
總結
以上是生活随笔為你收集整理的Java迭代器修改链表_Java恼人的迭代器不会返回链表中的元素的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ctbclick.exe是什么进程 会弹
- 下一篇: ctdvddet.exe是什么软件的文件