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

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

Description

Creates a new list containing the objects in the object array.

License

Open Source License

Declaration

public static <T> List<T> newList(T... objects) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    /**/*from  w w w.  j  a v a  2s  . co m*/
     * Creates a new list containing the objects in the object array.
     */
    public static <T> List<T> newList(T... objects) {
        List list = new ArrayList(objects.length);
        for (Object object : objects)
            list.add(object);
        return list;
    }

    /**
     * Adds an object to the given list and returns list (creates list if missing).
     */
    public static <T> List<T> add(List<T> aList, T anObj) {
        // If list is null, create list
        if (aList == null)
            aList = new Vector();

        // Add object
        aList.add(anObj);

        // Return list
        return aList;
    }
}

Related

  1. newList(int... sizes)
  2. newList(T... elements)
  3. newList(T... elements)
  4. newList(T... items)
  5. newList(T... list)
  6. newList(T... objs)
  7. newList(T... ts)
  8. newList(T... values)
  9. newList(V... items)