Java Set Create asSet(T... elements)

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

Description

Creates a java.util.Set with the given elements.

License

Apache License

Parameter

Parameter Description
elements the elements.
T the element type.

Exception

Parameter Description
NullPointerException if parameter elements is null.

Return

a new instance containing the given elements.

Declaration

public static <T> Set<T> asSet(T... elements) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.LinkedHashSet;
import java.util.Set;
import static java.util.Collections.addAll;

public class Main {
    /**//from   w w  w. ja  v a 2s .c o  m
     * Creates a {@link java.util.Set} with the given elements.
     *
     * @param elements the elements.
     * @param <T>      the element type.
     * @return a new {@link java.util.Set} instance containing the given elements.
     * @throws NullPointerException if parameter elements is {@code null}.
     */
    public static <T> Set<T> asSet(T... elements) {
        final Set<T> resultSet = new LinkedHashSet<T>();
        addAll(resultSet, elements);

        return resultSet;
    }
}

Related

  1. asSet(T... array)
  2. asSet(T... array)
  3. asSet(T... element)
  4. asSet(T... elements)
  5. asSet(T... elements)
  6. asSet(T... items)
  7. asSet(T... ts)
  8. asSet(T... ts)
  9. asSet(T... values)