Java List from listOf(Collection collection, T... elements)

Here you can find the source of listOf(Collection collection, T... elements)

Description

list Of

License

Open Source License

Declaration

public static <T> List<T> listOf(Collection<T> collection, T... elements) 

Method Source Code


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

import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    public static <T> List<T> listOf(Collection<T> collection, T... elements) {
        return (List<T>) fillCollection(fillCollection(newList(), collection), elements);
    }//w  w w . ja  va  2s. c  o m

    public static <T> List<T> listOf(Collection<T> collectionA, Collection<T> collectionB) {
        return (List<T>) fillCollection(fillCollection(newList(), collectionA), collectionB);
    }

    public static <T> List<T> listOf(T... elements) {
        return (List<T>) fillCollection(newList(), elements);
    }

    private static <T> Collection<T> fillCollection(Collection<T> myCollection, T[] elements) {
        if (elements != null) {
            for (T element : elements) {
                myCollection.add(element);
            }
        }
        return myCollection;
    }

    private static <T> Collection<T> fillCollection(Collection<T> myCollection, Collection<T> elements) {
        if (elements != null) {
            myCollection.addAll(elements);
        }
        return myCollection;
    }

    private static <T> List<T> newList() {
        return new ArrayList<T>();
    }
}

Related

  1. listOf(A... values)
  2. listOf(A[] objs)
  3. listOf(Class type)
  4. listOf(Collection coll)
  5. listOf(Collection... elts)
  6. listOf(double... values)
  7. listOf(E... elements)
  8. listOf(E... elements)