Iterators vs Iterable
From charlesreid1
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
See Java/Iterable and Java/Iterator for examples.