Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 2
    By implementing Iterator, you only guarantee that it has an end eventually. You could in theory create a RandomCardIterator that gives you random cards until you've consumed all cards in a deck. What he's probably thinking of is ListIterator which does guarantee a specific ordering. Commented Jun 4, 2015 at 14:23
  • 3
    @Neil I haven't seen anything in Iterator that implies that it ends as part of the contract, just that it will tell you when it ends if it does. I've seen class Primes implements Iterator<Long> { public boolean hasNext() { return true; } ... } Commented Jun 4, 2015 at 14:47
  • @MichaelT Honestly, neither have I, though it'd only take a for(Element ele : elements) to create an infinite loop in that case. I would say Streams are better suited for that sort of thing. Commented Jun 4, 2015 at 14:50
  • I understood that Set (implicitly) disallowed duplicates while Collection does allow it. Commented Jun 4, 2015 at 15:07
  • 1
    @Neil if the code ever goes through a process where Java 8 is acceptable then that would be a consideration. For a 1.6 world, this was a way of doing a lazy list of Primes. Commented Jun 4, 2015 at 15:12