Java Set Create asSet(final E... elements)

Here you can find the source of asSet(final E... elements)

Description

Creates an immutable HashSet instance containing the given elements in unspecified order.

License

Open Source License

Parameter

Parameter Description
E a parameter
elements the elements that the set should contain

Return

a new HashSet containing those elements (minus duplicates)

Declaration

public static <E> Set asSet(final E... elements) 

Method Source Code

//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);
    }
}

Related

  1. asSet(Collection c)
  2. asSet(Collection c)
  3. asSet(Collection c)
  4. asSet(E... elements)
  5. asSet(E... pEntities)
  6. asSet(final T t, final T... ts)
  7. asSet(final T... array)
  8. asSet(int... values)
  9. asSet(Iterable iteratable)