Java List Create createList(T... items)

Here you can find the source of createList(T... items)

Description

Create a new array list from the specified list of items.

License

Open Source License

Parameter

Parameter Description
items The items to add to the list

Declaration

public static <T> List<T> createList(T... items) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.Collections;
import java.util.List;

public class Main {
    /**/*from ww w.  java2s  .co  m*/
     * Create a new array list from the specified list of items. It is expected
     * that all items are of the same type.
     * 
     * @param items
     *            The items to add to the list
     * @return
     */
    public static <T> List<T> createList(T... items) {
        List<T> result;

        if (items != null && items.length > 0) {
            result = new ArrayList<T>(items.length);

            for (int i = 0; i < items.length; i++) {
                result.add(items[i]);
            }
        } else {
            result = Collections.emptyList();
        }

        return result;
    }
}

Related

  1. createList(String s)
  2. createList(T value, int n)
  3. createList(T... _entries)
  4. createList(T... array)
  5. createList(T... element)
  6. createList(T... items)
  7. createList(T... objs)
  8. createList(T... params)
  9. createListFrom(String... array)