Here you can find the source of toCollection(final Iterable
Iterable
into a Collection
.
Parameter | Description |
---|---|
iterable | the iterable to convert |
Collection
containing all elements of the iterable
public static <E> Collection<E> toCollection(final Iterable<E> iterable)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class Main { /**//from w w w . j av a2 s . co m * Converts an <code>Iterable</code> into a <code>Collection</code>. This * method returns an <code>ArrayList</code> containing all elements returned * by the iterator generated by <code>iterable</code> in the order they are * returned. * * @param iterable the iterable to convert * @return a <code>Collection</code> containing all elements of the iterable */ public static <E> Collection<E> toCollection(final Iterable<E> iterable) { final Collection<E> col = new ArrayList<E>(); final Iterator<E> it = iterable.iterator(); while (it.hasNext()) { final E item = it.next(); col.add(item); } return col; } }