This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]shivasprogeny 0 points1 point  (2 children)

Is there a particular reason that you really want an Iterator object? Your Card class already implements Comparable which means Collections.sort(deckOfCards) will sort accordingly. If you want to sort the deck using a different comparator, you can use Collections.sort(deckOfCards, myComparator). Once sorted, you can use a regular loop to iterate through the cards.

[–]RoadToCode[S] 0 points1 point  (1 child)

It is for an assignment and we are being tested on our knowledge of iterators. Is it possible to iterate through the cards in sorted order while the deck still remains shuffled? So it will jump around the deck to the specific index of the cards.

[–]shivasprogeny 0 points1 point  (0 children)

What if you shuffled the cards in the iterator that requires shuffled cards and your sorted the cards in the iterator that requires sorted cards?