create HashSet from varargs - Java java.util

Java examples for java.util:HashSet

Description

create HashSet from varargs

Demo Code


//package com.book2s;

import java.util.Collection;

import java.util.HashSet;

public class Main {

    public static final <E> HashSet<E> createHashSet(E... elements) {
        HashSet<E> list = new HashSet<E>();
        addToCollection(list, elements);
        return list;
    }//from  ww w  .j a v  a2 s. c  om

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

Related Tutorials