Joins some Iterable s to a single one. - Java Collection Framework

Java examples for Collection Framework:Iterable

Description

Joins some Iterable s to a single one.

Demo Code


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class Main{
    /**//from   w  w w.jav a 2s.  c  o m
     * Joins some {@link Iterable}s to a single one.
     *
     * @param iterables
     *          A set of {@link Iterable}s to join to a single {@link Iterable}.<br>
     *          May contain <code>null</code>s.
     * @return A single {@link Iterable}. Never <code>null.</code>
     */
    @SuppressWarnings("unchecked")
    public static <T> Iterable<T> join(Iterable<? extends T>... iterables) {
        if (iterables.length == 0) {
            return Collections.emptyList();
        }
        if (iterables.length == 1) {
            return (Iterable<T>) iterables[0];
        }
        return new IterableChain<T>(iterables);
    }
}

Related Tutorials