Tech and Media Labs
This site uses cookies to improve the user experience.




Java Collections - Iterable

Jakob Jenkov
Last update: 2014-06-23

The Iterable interface (java.lang.Iterable) is one of the root interfaces of the Java collection classes. The Collection interface extends Iterable, so all subtypes of Collection also implement the Iterable interface.

A class that implements the Iterable can be used with the new for-loop. Here is such an example:

List list = new ArrayList();

for(Object o : list){
    //do something o;    
}

The Iterable interface has only one method:

public interface Iterable<T> {
  public Iterator<T> iterator();    
}

How you implement this Iterable interface so that you can use it with the new for-loop, is explained in the text Implementing the Iterable Interface, in my Java Generics tutorial.

Jakob Jenkov




Copyright  Jenkov Aps
Close TOC