Here you can find the source of asSet(final E... elements)
Parameter | Description |
---|---|
E | a parameter |
elements | the elements that the set should contain |
public static <E> Set asSet(final E... elements)
//package com.java2s; //License from project: Open Source License import java.util.Collections; import java.util.HashSet; import java.util.Set; public class Main { /**//from w w w . j a v a 2 s . c om * Creates an <i>immutable</i> {@code HashSet} instance containing the given * elements in unspecified order. * * @param <E> * @param elements the elements that the set should contain * @return a new {@code HashSet} containing those elements (minus * duplicates) */ public static <E> Set asSet(final E... elements) { if (elements == null) { return new HashSet<>(0); } final Set<E> set = new HashSet<>(elements.length); Collections.addAll(set, elements); return Collections.unmodifiableSet(set); } }