Java ArrayList Create newArrayList()

Here you can find the source of newArrayList()

Description

new Array List

License

Open Source License

Declaration

public static <T> ArrayList<T> newArrayList() 

Method Source Code


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

import java.util.List;

public class Main {
    public static <T> ArrayList<T> newArrayList() {
        return new ArrayList<>();
    }//from   www.  j  a  v a  2 s  .  c om

    @SuppressWarnings("unchecked")
    public static <T> ArrayList<T> newArrayList(T... elements) {
        ArrayList<T> list = newArrayList();
        addElements(list, elements);
        return list;
    }

    public static <T> ArrayList<T> newArrayList(int capacity) {
        return new ArrayList<>(capacity);
    }

    public static <T> ArrayList<T> newArrayList(Collection<? extends T> c) {
        return new ArrayList<>(c);
    }

    public static <T> boolean addElements(List<T> list, T[] array) {
        boolean good = true;
        for (T obj : array) {
            good &= list.add(obj);
        }
        return good;
    }
}

Related

  1. newArrayList()
  2. newArrayList()
  3. newArrayList()
  4. newArrayList()
  5. newArrayList()
  6. newArrayList(A... elements)
  7. newArrayList(Collection c)
  8. newArrayList(Collection collection)
  9. newArrayList(E... elements)