Copies an iterable's elements into an array.

@param iterable the iterable to copy
@param type the type of the elements
@return a newly-allocated array into which all the elements of the iterable
have been copied
481035
@GwtIncompatible("Array.newInstance(Class, int)")
  public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type) {
    Collection<? extends T> collection = toCollection(iterable);
    T[] array = ObjectArrays.newArray(type, collection.size());
    return collection.toArray(array);
  }
622685
public static <T> List<T> toList(Iterable<T> iterable) {
        List<T> list = null;

        if (iterable != null) {
            list = new ArrayList<>();
            for (T elem : iterable) {
                list.add(elem);
            }
        }

        return list;
    }
488731
@SuppressWarnings("unchecked")
    public static <E> E[] toArray(final Iterable<E> iterable) {
        return (E[]) newArrayList(iterable).toArray();
    }
42216
public static <E> ArrayList<E> newArrayList(Iterable<? extends E> elements) {
		return (elements instanceof Collection) ? new ArrayList<E>((Collection<? extends E>)elements)
				: newArrayList(elements.iterator());
	}
633809
@SafeVarargs
    @SuppressWarnings("unchecked")
    public static <T> Iterable<T> compositeIterable(Iterable<T>...iterables) {
        Require.nonNull(iterables, "iterables");
        final Iterator<T> it;
        if (iterables.length == 0) {
            it = Collections.emptyIterator();
        } else if (iterables.length == 1) {
            return iterables[0];
        } else {
            final Iterator<T>[] iterators = Arrays.stream(iterables)
                    .map(Iterable::iterator)
                    .toArray(size -> new Iterator[size]);
            it = new CompoundIterator<T>(iterators);
        }
        return iterableOf(it);
    }
223141
public static <T> ArrayList<T> newArrayList(Iterable<T> elements) {
		return Lists.newArrayList(elements);
	}
622066
public Iterable<T> filter(final Iterable<T> iterable) {
        return new Iterable<T>() {

            @Override
            public Iterator<T> iterator() {
                return filter(iterable.iterator());
            }
        };
    }
654729
public static <T> List<T> iterToList(final Iterable<T> it) {
        if (it instanceof List) {
            return (List<T>) it;
        }
        if (it == null) {
            return null;
        }

        final List<T> ar = new ArrayList<T>();
        for (final T o : it) {
            ar.add(o);
        }

        return ar;
    }
498671
public static <E> ImmutableList<E> copyOf(E[] elements) {
    switch (elements.length) {
      case 0:
        return ImmutableList.of();
      case 1:
        return new SingletonImmutableList<E>(elements[0]);
      default:
        return new RegularImmutableList<E>(checkElementsNotNull(elements.clone()));
    }
  }
1283143
@SafeVarargs
  /* #end */
  public static <KType> KTypeArrayDeque<KType> from(KType... elements)
  {
      final KTypeArrayDeque<KType> coll = new KTypeArrayDeque<KType>(elements.length);
      coll.addLast(elements);
      return coll;
  }
280357
public static <T> boolean addAllIterable(Iterable<? extends T> iterable, Collection<T> targetCollection)
    {
        if (iterable == null)
        {
            throw new NullPointerException();
        }
        if (iterable instanceof Collection<?>)
        {
            return targetCollection.addAll((Collection<T>) iterable);
        }
        int oldSize = targetCollection.size();
        Iterate.forEachWith(iterable, Procedures2.<T>addToCollection(), targetCollection);
        return targetCollection.size() != oldSize;
    }
1084570
public static <T> List<T> toList(TypedIterable<T> iterable) {
        List<T> result = new ArrayList<>();
        for (T item : iterable) {
            result.add(item);
        }
        return result;
    }
314579
public static <T> List<T> toList(Iterable<T> iterable)
    {
        Objects.requireNonNull(iterable, "The iterable is null");
        return Iterables.toCollection(iterable, new ArrayList<T>());
    }
104066
public static <T> Set<T> toSet(Iterable<T> iterable)
   {
      if (iterable == null)
      {
         return null;
      }
      else if (iterable instanceof Set)
      {
         return (Set<T>) iterable;
      }
      else
      {
         Set<T> list = new LinkedHashSet<>();
         for (T obj : iterable)
         {
            list.add(obj);
         }
         return list;
      }
   }
999724
public static <T> Iterable<T> concat(final Iterable<? extends Iterable<? extends T>> iterables) {
        return () -> Iterators.concat(iterators(iterables));
    }
603747
public static <T> Object[] toArray(Iterable<T> iterable)
    {
        if (iterable == null)
        {
            throw new NullPointerException();
        }
        if (iterable instanceof Collection)
        {
            return ((Collection<T>) iterable).toArray();
        }
        if (iterable instanceof RichIterable)
        {
            return ((RichIterable<T>) iterable).toArray();
        }
        MutableList<T> result = Lists.mutable.empty();
        Iterate.addAllTo(iterable, result);
        return result.toArray();
    }
927794
public static <E> E sample(final Iterable<E> iterable) {
        return newArrayList(iterable).get(new java.security.SecureRandom().nextInt(size(iterable)));
    }