1.Iterable接口与Collection:由于Collection集合(List、Set、Queue)继承了Iterable接口,因此迭代及foreach适用于任何Collection对象。
2.Iterable接口与Map:由于Map接口没有继承Iterable接口,因此Map对象不能直接使用迭代及foreach,但是Map.entrySet()、Map.keySet()、Map.valueSet()返回的是Set,所以迭代可用于Map.entrySet()、Map.keySet()、Map.valueSet()。
任何实现了Iterable的类都可用于迭代器及foreach语句中。
从Iterable接口的源码可知,foreach是Iterable接口的方法