Returns a {List} of the contents for the given {Iterable} - Java Collection Framework

Java examples for Collection Framework:Iterable

Description

Returns a {List} of the contents for the given {Iterable}

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/* w ww .  ja  v  a  2s  .c om*/
     * Returns a {List} of the contents for the given {Iterable}
     *
     * @param iterable The Iterable
     * @param <T>      The type of objects contained in the {Iterable}
     * @return A {List} of the iterable's objects
     */
    public static <T> List<T> asList(Iterable<T> iterable) {
        List<T> list = new ArrayList<T>();

        for (T item : iterable) {
            list.add(item);
        }

        return list;
    }
}

Related Tutorials