Start by considering the conditions for ending the loop:
public boolean hasNext(){
return current != null;
}
This means that the last time it is executed, it will return null
, since it checks that the current element, and not the next element, is non-zero.
So your code will become something like this:
Integer it_next = null;
assertEquals(i, (int)it_next);
int
- , . unboxing, , :
r Integer, unboxing r r.intValue()
,
((Integer)null).intValue();
, .
, , , - true
hasNext
, next
null
. - :
public boolean hasNext(){
return current != null && current.next != null;
}