create LinkedHashSet from varargs - Java java.util

Java examples for java.util:LinkedHashSet

Description

create LinkedHashSet from varargs

Demo Code


//package com.book2s;

import java.util.Collection;

import java.util.LinkedHashSet;

public class Main {

    public static final <E> LinkedHashSet<E> createLinkedHashSet(
            E... elements) {/*  w  w w  .  java2 s.  c om*/
        LinkedHashSet<E> list = new LinkedHashSet<E>();
        addToCollection(list, elements);
        return list;
    }

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

Related Tutorials