Java tutorial
//package com.java2s; import java.util.Iterator; public class Main { public static <T> Iterable<T> cycle(final Iterable<T> it) { return new Iterable<T>() { public Iterator<T> iterator() { return new Iterator<T>() { private Iterator<T> nextCycle = it.iterator(); public boolean hasNext() { return true; // forever cycles } public T next() { if (!nextCycle.hasNext()) { nextCycle = it.iterator(); // create the next cycle } return nextCycle.next(); } }; } }; } }