From charlesreid1

Revision as of 09:36, 25 June 2017 by Admin (talk | contribs) (Created page with "In Java, there are two mechanisms to allow you to deal with iteration: * Iterable is a generic approach to getting an iterator. It enables an object to support for-each syntax...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In Java, there are two mechanisms to allow you to deal with iteration:

  • Iterable is a generic approach to getting an iterator. It enables an object to support for-each syntax. It is not concerned with how the iterator works, where it starts or stops, etc. It just returns the iterator. If you implement Iterable<E> you just need to be able to provide an Iterator<E>.
  • Iterator is a simple wrapper class (like a Scanner object) that just supports a few operations for getting the next item in an object/collection