Java Collection Create toCollection(Iterable i)

Here you can find the source of toCollection(Iterable i)

Description

Convert an Iterable to a Collection (ArrayList under the hood).

License

Apache License

Parameter

Parameter Description
i a parameter

Declaration

public static <T> Collection<T> toCollection(Iterable<T> i) 

Method Source Code


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

import java.util.ArrayList;
import java.util.Collection;

public class Main {
    /**/*from   w w w .ja va 2  s .  c om*/
     * Convert an Iterable to a Collection (ArrayList under the hood). All items in the
     * Iterable will be retained.
     * @param i
     * @return
     */
    public static <T> Collection<T> toCollection(Iterable<T> i) {
        if (i == null) {
            throw new IllegalArgumentException("Iterable 'i' cannot be null");
        }
        Collection<T> c = new ArrayList<T>();
        for (T t : i) {
            c.add(t);
        }
        return c;
    }
}

Related

  1. toCollection(Class cls, T[] array)
  2. toCollection(final char[] charArray)
  3. toCollection(final Iterable iterable)
  4. toCollection(final T[] elements)
  5. toCollection(Iterable iterable)
  6. toCollection(Object o)
  7. toCollection(String value)