Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /** * Create a list out of the items in the Iterable. * * @param <T> * The type of items in the Iterable. * @param items * The items to be made into a list. * @return A list consisting of the items of the Iterable, in the same order. */ public static <T> List<T> toList(Iterable<T> items) { List<T> list = new ArrayList<T>(); addAll(list, items); return list; } /** * Add all the items from an iterable to a collection. * * @param <T> * The type of items in the iterable and the collection * @param collection * The collection to which the items should be added. * @param items * The items to add to the collection. */ public static <T> void addAll(Collection<T> collection, Iterable<? extends T> items) { for (T item : items) { collection.add(item); } } }