Converts an {@link Iterable} to a {@link List}.

@param iterable The iterable
@param <T>      The generic type
@return The list
420657
public static <T> List<T> iterableToList(Iterable<T> iterable) {
        if (iterable == null) {
            return Collections.emptyList();
        }
        if (iterable instanceof List) {
            return (List<T>) iterable;
        }
        Iterator<T> i = iterable.iterator();
        if (i.hasNext()) {
            List<T> list = new ArrayList<>();
            while (i.hasNext()) {
                list.add(i.next());
            }
            return list;
        }
        return Collections.emptyList();
    }
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();
    }
1132404
public static <T> Gather<T> from(Iterable<T> iterable) {
		return null == iterable 
				? Gather.<T>empty() : from(iterable.iterator());
	}
1097984
public static <T> Predicate<T> contains(final Iterable<T> iterable) {
        return new Predicate<T>() {
            @Override
            public boolean test(final T testValue) {
                return Iterables.contains(iterable, testValue);
            }
        };
    }
1120457
@SuppressWarnings("unchecked")
    public static <T> T asType(Iterable iterable, Class<T> clazz) {
        if (Collection.class.isAssignableFrom(clazz)) {
            return asType((Collection) toList(iterable), clazz);
        }

        return asType((Object) iterable, clazz);
    }
371997
public static <T> T head(Iterable<T> iterable) {
		return IteratorExtensions.head(iterable.iterator());
	}
1235691
public <T extends Comparable<? super T>> List<T> sort (Iterator<T> iter)
    {
        ArrayList<T> list = new ArrayList<T>();
        CollectionUtil.addAll(list, iter);
        return sort(list);
    }
502702
public static <T> List<T> toList(Iterator<T> self) {
        List<T> answer = new ArrayList<T>();
        while (self.hasNext()) {
            answer.add(self.next());
        }
        return answer;
    }
575734
public static <T> List<T> toList(Iterator<T> iter) {
    List<T> buf = new ArrayList<>();
    while (iter.hasNext()) {
      buf.add(iter.next());
    }
    return buf;
  }
497925
public final List<T> toList() {
        List<T> list = new ArrayList<T>();
        return into(list);
    }
647155
public static <E> List<E> asList(Iterable<E> i) {
        if (i instanceof Collection) {
            return new ArrayList<E>((Collection<E>) i);
        }
        ArrayList<E> a = new ArrayList<E>();
        for (E e : i) {
            a.add(e);
        }
        return a;
    }
662337
public static <T> List<T> list(boolean isLinked, Iterable<T> iterable) {
		if (null == iterable) {
			return list(isLinked);
		}
		return list(isLinked, iterable.iterator());
	}
368760
public static <T> T last(Iterable<T> iterable) {
		if (iterable instanceof List<?>) {
			List<T> list = (List<T>) iterable;
			if (list.isEmpty())
				return null;
			return list.get(list.size() - 1);
		} else if (iterable instanceof SortedSet) {
			SortedSet<T> sortedSet = (SortedSet<T>) iterable;
			if (sortedSet.isEmpty())
				return null;
			return sortedSet.last();
		} else {
			return IteratorExtensions.last(iterable.iterator());
		}
	}
925597
public static <T> List<T> asList(Iterable<T> iterable) {
        List<T> result = new ArrayList<>();
        for (T item : iterable) {
            result.add(item);
        }
        return result;
    }
110851
public static <T> C.List<T> toList(Iterator<? extends T> iterator) {
        ListBuilder<T> lb = new ListBuilder<T>(10);
        lb.append(iterator);
        return lb.toList();
    }
107385
public static <T> Set<T> asSet(final Iterable<T> iterable)
   {
      Set<T> result = new HashSet<T>();
      for (T t : iterable)
      {
         result.add(t);
      }
      return result;
   }
1040216
public static @Nonnull <T> Iterable<T> enumerationToIterable(@Nullable Enumeration<T> enumeration) {
        if (enumeration == null) {
            return Collections.emptyList();
        }

        return () -> new Iterator<T>() {
            @Override
            public boolean hasNext() {
                return enumeration.hasMoreElements();
            }

            @Override
            public T next() {
                return enumeration.nextElement();
            }
        };
    }