Java List Create createList(Collection collection)

Here you can find the source of createList(Collection collection)

Description

Creates a new list from the given collection.

License

Open Source License

Parameter

Parameter Description
collection the collection

Return

the list

Declaration

@SuppressWarnings({ "unchecked", "rawtypes" })
public static List createList(Collection collection) 

Method Source Code


//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]);
        }
    }
}

Related

  1. createLimitSql(StringBuilder sql, Integer startNum, Integer rowNum, List params)
  2. createList( Iterator iterator )
  3. createList()
  4. createList(Class elementClass)
  5. createList(Class itemClazz, T... items)
  6. createList(Collection collection)
  7. createList(Collection collection)
  8. createList(E initialElement)
  9. createList(final T object)

  10. HOME | Copyright © www.java2s.com 2016