Campbell Ritchie wrote:The Iterable<E> interface was introduced in Java5 along with the for-each loop; the two support each other. Any collections class which supported the iterator() method was retrofitted to implement the Iterable<E> interface. The way this was done was to change the Collection<E> interface to Collection<E> extends Iterable<E>. Since interfaces like Set<T> and List<T> already extend Collection<T>, this means any List<E> or Set<E>, etc. is also an Iterable<E>. The iterator() method was put into the Iterable<E> interface (I can’t remember whether it is removed from Collection<E> or not).
Maps<K, V> have never implemented an iterator() method, because you never go through a Map<K, V>. You go through its Ks or its Vs, so you can get them as a Set<K> or a Set<V>, which you can traverse with a for-each loop, since th/ose are now Iterable<E> objects.