Java ArrayList Create createArrayList()

Here you can find the source of createArrayList()

Description

create Array List

License

Open Source License

Declaration

public static <E> ArrayList<E> createArrayList() 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

import java.util.Collection;

public class Main {

    public static <E> ArrayList<E> createArrayList() {
        return new ArrayList<E>();
    }/*  w  ww .ja  v a 2s  .c o  m*/

    public static <E> ArrayList<E> createArrayList(int initialCapacity) {
        return new ArrayList<E>(initialCapacity);
    }

    public static <E> ArrayList<E> createArrayList(Collection<? extends E> collection) {
        if (collection == null) {
            return new ArrayList<E>();
        }

        return new ArrayList<E>(collection);
    }

    public static <E> ArrayList<E> createArrayList(Iterable<? extends E> iter) {

        if (iter instanceof Collection<?>) {
            return new ArrayList<E>((Collection<? extends E>) iter);
        }

        ArrayList<E> list = new ArrayList<E>();

        iterableToCollection(iter, list);

        list.trimToSize();

        return list;
    }

    public static <T, V extends T> ArrayList<T> createArrayList(V... args) {
        if (args == null || args.length == 0) {
            return new ArrayList<T>();
        }

        ArrayList<T> list = new ArrayList<T>(args.length);

        for (V v : args) {
            list.add(v);
        }

        return list;

    }

    private static <E> void iterableToCollection(Iterable<? extends E> iter, Collection<E> list) {
        if (iter == null) {
            return;
        }

        for (E element : iter) {
            list.add(element);
        }
    }
}

Related

  1. asArrayList(Collection list)
  2. asArrayList(Collection collection)
  3. createArrayList()
  4. createArrayList(Collection arg)
  5. createArrayList(E... array)
  6. createArrayList(final DataType first, final DataType second)
  7. createArrayList(Iterable items, int size)