Java ArrayList Create newArrayList(T... elements)

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

Description

Avoid dependency on Guava types

License

Open Source License

Declaration

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

Method Source Code

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

import java.util.*;

public class Main {
    /***//from ww  w.  j a  v a 2  s  .c o m
     * Avoid dependency on Guava types
     */
    @SafeVarargs
    public static <T> List<T> newArrayList(T... elements) {
        List<T> list = new ArrayList<>(1);
        Collections.addAll(list, elements);
        return list;
    }

    public static <T> List<T> newArrayList(T element) {
        List<T> list = new ArrayList<>(1);
        list.add(element);
        return list;
    }
}

Related

  1. newArrayList(int initialCapacity)
  2. newArrayList(int size)
  3. newArrayList(Iterable elements)
  4. newArrayList(Iterable iterable)
  5. newArrayList(T anObj)
  6. newArrayList(T... items)
  7. newArrayList(T... objectList)
  8. newArrayList(T... objs)
  9. newArrayList(X... args)