【发布时间】:2011-03-26 20:40:55
【问题描述】:
这是我尝试获取迭代器的两个连续元素的代码。
public void Test(Iterator<Value> values) {
Iterator<Value> tr = values;
while (tr.hasNext()) {
v = tr.next();
x = v.index1;
// u = null;
if (tr.hasNext()) {
u = tr.next();
y = u.index1;
} else {
u = v;
y = u.index1;
}
System.out.println(x);
System.out.println(y);
}
}
但我仍然得到相同的 x 和 Y 值。
这有什么问题,我得到的两个变量 x 和 y 的值相同。
【问题讨论】:
标签: java collections iterator