Java List Create createList(final T... elements)

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

Description

Creates a list of the given type for the given elements.

License

BSD License

Parameter

Parameter Description
T The type of the elements and the list.
elements The elements to add to the list.

Return

The filled list.

Declaration

public static <T> List<T> createList(final T... elements) 

Method Source Code


//package com.java2s;
//License from project: BSD License 

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

public class Main {
    /**/*  w  w  w. j  av a 2s . co m*/
     * Creates a list of the given type for the given elements.
     * 
     * @param <T>
     *            The type of the elements and the list.
     * @param elements
     *            The elements to add to the list.
     * @return The filled list.
     */
    public static <T> List<T> createList(final T... elements) {
        if (elements == null) {
            return new ArrayList<T>();
        } else {
            return new ArrayList<T>(Arrays.asList(elements));
        }
    }
}

Related

  1. createList(Collection collection)
  2. createList(Collection collection)
  3. createList(Collection collection)
  4. createList(E initialElement)
  5. createList(final T object)
  6. createList(List list)
  7. createList(Object... entries)
  8. createList(Object... objs)
  9. createList(Object[] values)