Java examples for java.util:List Operation
Returns of linked list of the objects given in the vararg.
//package com.java2s; import java.util.*; public class Main { /**//from w ww .java 2 s . c o m * Returns of linked list of the objects given in the vararg. * * @param contents the objects to return in the list. * @param <T> the class the given objects are instantiations of. * @return a linked list containing the given contents. * @throws AssertionError if any of the contents are not the same type. */ public static <T> List<T> listOf(T... contents) { // Check all items in set are of same type... Class first_class = null; for (Object item : contents) { if (first_class == null) { first_class = item.getClass(); } else { assert first_class == item.getClass(); } } return new LinkedList<T>(Arrays.asList(contents)); } }