Java Iterable to List iterableToCollection(Iterable c, Collection list)

Here you can find the source of iterableToCollection(Iterable c, Collection list)

Description

iterable To Collection

License

Apache License

Declaration

private static <T> void iterableToCollection(Iterable<? extends T> c, Collection<T> list) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

import java.util.List;

public class Main {
    private static <T> void iterableToCollection(Iterable<? extends T> c, Collection<T> list) {
        for (T element : c) {
            list.add(element);/*from   ww  w.  j  a va2  s  . c  om*/
        }
    }

    /**
     * Adds the given item to the list at specified <code>index</code>.
     * <p/>
     * if <code>index</code> is greater than list size, it simply appends to the
     * list.
     * 
     * @param list
     *            collection of elements
     * @param index
     *            specific index
     * @param item
     *            object to add.
     */
    public static <E, T extends E> void add(List<E> list, int index, T item) {
        if (index < list.size()) {
            list.add(index, item);
        } else {
            list.add(item);
        }
    }
}

Related

  1. iterable2List(Iterable iterable)
  2. iterableAsList(Iterable iterable)
  3. iterableToCollection(Iterable c, Collection list)
  4. iterableToList(Iterable iterable)
  5. iterableToList(Iterable input)
  6. iterableToList(Iterable iterable)