When executing my program it keeps displaying "null" on line 13 I want to know what's wrong on my algorithm for it keeps printing null.
private class SpadeIterator implements Iterator<Card>{
private int nextCardSpade;
private List<Card> cards;
private int count=0;
private SpadeIterator(List cards) {
this.cards=cards;
this.nextCardSpade = cards.size()-1;
}
@Override
public boolean hasNext() {
count++;
if(nextCardSpade<0)
return false;
//nextCardSpade--;
return true;
}
@Override
public Card next() {
int i=0;
this.count=i;
Card temp = cards.get(nextCardSpade);
while(hasNext()){ //find SPADES
temp=cards.get(nextCardSpade--);
i++;
if(temp.suit.value == Suit.SPADES.value)
return temp;
}
//DONT MOVE
return null;
//nextCardSpade--; //DONT DELETE
}
}
The results are meant to show the 13 spades without returning null at the end.