create Linked List from varargs - Java java.util

Java examples for java.util:List Creation

Description

create Linked List from varargs

Demo Code


//package com.book2s;

import java.util.Collection;

import java.util.LinkedList;

public class Main {

    public static final <E> LinkedList<E> createLinkedList(E... elements) {
        LinkedList<E> list = new LinkedList<E>();
        addToCollection(list, elements);
        return list;
    }/*from   w w w  .  j  a va  2 s.  c o m*/

    public static final <E> void addToCollection(
            Collection<? super E> collection, E... elements) {
        for (E e : elements) {
            collection.add(e);
        }
    }
}

Related Tutorials