返回给定{Iterable}的内容的{List}
//时代Java - N o w J a v a . c o m 提供 //package com.nowjava; import java.util.ArrayList; import java.util.List; public class Main { /** * Returns a {List} of the contents for the given {Iterable} * * @param iterable The Iterable * @param <T> The type of objects contained in the {Iterable} * @return A {List} of the iterable's objects */ public static <T> List<T> asList(Iterable<T> iterable) { List<T> list = new ArrayList<T>(); for (T item : iterable) { list.add(item); } return list; } }