cycle Iterable
Returns an iterable whose iterators cycle indefinitely over the elements of this.
Warning: Typical uses of the resulting iterator may produce an infinite loop. You should use an explicit break or be certain that you will eventually remove all the elements.
To cycle over the iterable n times, use the following: Iterables.concat(Collections.nCopies(n, iterable))
Java 8 users: The Stream equivalent of this method is Stream.generate(() -> iterable).flatMap(Streams::stream).
See also
Returns an iterable whose iterators cycle indefinitely over the elements of this.
That iterator supports remove if iterable.iterator() does. After remove is called, subsequent cycles omit the removed element, which is no longer in this. The iterator's hasNext method returns true until this is empty.
Warning: Typical uses of the resulting iterator may produce an infinite loop. You should use an explicit break or be certain that you will eventually remove all the elements.
To cycle over the iterable n times, use the following: Iterables.concat(Collections.nCopies(n, iterable))
Java 8 users: The Stream equivalent of this method is Stream.generate(() -> iterable).flatMap(Streams::stream).
See also
Returns an iterable whose iterators cycle indefinitely over the provided elements.
After remove is invoked on a generated iterator, the removed element will no longer appear in either that iterator or any other iterator created from the same source iterable. That is, this method behaves exactly as Iterables.cycle(Lists.newArrayList(elements)). The iterator's hasNext method returns true until all of the original elements have been removed.
Warning: Typical uses of the resulting iterator may produce an infinite loop. You should use an explicit break or be certain that you will eventually remove all the elements.
To cycle over the elements n times, use the following: Iterables.concat(Collections.nCopies(n, Arrays.asList(elements)))
Java 8 users: If passing a single element e, the Stream equivalent of this method is Stream.generate(() -> e). Otherwise, put the elements in a collection and use Stream.generate(() -> collection).flatMap(Collection::stream).