Create new HashSet by variable length parameter - Java java.util

Java examples for java.util:HashSet

Description

Create new HashSet by variable length parameter

Demo Code


//package com.book2s;

import java.util.HashSet;

public class Main {
    public static void main(String[] argv) {
        System.out.println(newHashSet());
    }// w w w.  j av a2  s . c o  m

    public static <T> HashSet<T> newHashSet() {
        return new HashSet<T>();
    }

    @SafeVarargs
    public static <T> HashSet<T> newHashSet(T... ts) {
        HashSet<T> set = new HashSet<T>();
        for (T t : ts) {
            set.add(t);
        }
        return set;
    }
}

Related Tutorials