Iterable

The Iterable interface(java.lang.iterable) is root interface of  java collections classes. Collection interface extends Iterable so all subtypes of Collection also implements Iterable interface.
A class implements the Iterable interface can be used with new for loop. check following example.

List list = new ArrayList();
for(Object o : list)
{
// do somethin with o
}

Iterable interface has only one method.
interface Iterable<T> {
public Iterator<T> iterator();
}

No comments:

Post a Comment