Here you can find the source of createList(Collection collection)
Parameter | Description |
---|---|
collection | the collection |
@SuppressWarnings({ "unchecked", "rawtypes" }) public static List createList(Collection collection)
//package com.java2s; /*/*from ww w. java 2 s .co m*/ * Ext GWT 2.2.5 - Ext for GWT * Copyright(c) 2007-2010, Ext JS, LLC. * licensing@extjs.com * * http://extjs.com/license */ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; public class Main { /** * Creates a new list from the given collection. * * @param collection the collection * @return the list */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static List createList(Collection collection) { if (collection instanceof List) { return (List) collection; } List list = new ArrayList(); Iterator it = collection.iterator(); while (it.hasNext()) { list.add(it.next()); } return list; } /** * Creates a new list and adds the element(s). * * @param element the item to add to the list * @return the new list */ @SuppressWarnings("rawtypes") public static List createList(Object... element) { List list = new ArrayList(); fill(list, element); return list; } /** * Populates a list with an array of elements. * * @param list the list * @param elements the elements to be added to the list */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static void fill(List list, Object[] elements) { for (int i = 0; i < elements.length; i++) { list.add(elements[i]); } } }