Here is my code that i tried to get two consecutive elements of Iterator.
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);
}
}
But still i am getting same values for x and Y.
What is wrong with this, i am getting the same value for the two variables x and y.