Java Array to List newList(T... elements)

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

Description

Create ArrayList with some elements contained.

License

Apache License

Parameter

Parameter Description
elements elements to be contained in the list.
T type of list elements

Return

list

Declaration

@SafeVarargs
public static <T> List<T> newList(T... elements) 

Method Source Code


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

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//from   w  w w .j  a  v a2 s. c om
     * Create {@link ArrayList} with some elements contained.
     * 
     * @param elements
     *            elements to be contained in the list.
     * @param <T>
     *            type of list elements
     * @return list
     */
    @SafeVarargs
    public static <T> List<T> newList(T... elements) {
        ArrayList<T> result = new ArrayList<>();
        for (T element : elements) {
            result.add(element);
        }
        return result;
    }
}

Related

  1. fromArray(T[] array, Class clazz)
  2. fromArray(T[] objects)
  3. newList(final T... elements)
  4. newList(final T... elements)
  5. newList(int... sizes)
  6. newList(T... elements)
  7. newList(T... items)
  8. newList(T... list)
  9. newList(T... objects)