The Java "for-each" loop construct will allow iteration over two types of objects:
T[]
(arrays of any type)java.lang.Iterable<T>
The Iterable<T>
interface has only one method: Iterator<T> iterator()
. This works on objects of type Collection<T>
because the Collection<T>
interface extends Iterable<T>
.