My code:
Object tempDifference;
Object testUser;
testUser = users.get(0);
it8 = difference_time.iterator();
it9 = users.iterator();
Object tempUser;
tempDifference = difference_time.get(0);
while (it9.hasNext()) {
tempUser = it9.next();
System.out.println(testUser+" "+tempUser);
if (testUser.equals(tempUser)) {
times.add(tempDifference);
testUser = tempUser;
} else {
times.add(value);
testUser = tempUser;
}
tempDifference = it8.next();
}
-
Input is:
1 2 2 -
Output is:
1 1 -
I want output
1 2
Why is it the bad output 1 1 on beginning ?
Most iterators start Before the first element, so the first call to next() moves them to the first element, not the second.
So, if users = {1, 2}, and boiling it down somewhat: