Creates a list from the vararg specified items in the order they were specified. - Java java.util

Java examples for java.util:List Creation

Description

Creates a list from the vararg specified items in the order they were specified.

Demo Code


//package com.java2s;
import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*from  www  .ja  v a 2 s. co  m*/
     * Creates a list from the vararg specified items in the order they were
     * specified.
     * 
     * @param <T>
     *   type of item in the list
     *   
     * @param items
     *   array of items to be added to the list
     *   
     * @return
     *   a list containing all the items supplied in the order supplied order
     */
    public static <T> List<T> newList(T... items) {
        List<T> list = new ArrayList<T>(items.length);
        for (T t : items) {
            list.add(t);
        }

        return list;
    }
}

Related Tutorials