Turns a list of vararg parameters into a set. - Java java.util

Java examples for java.util:List Operation

Description

Turns a list of vararg parameters into a set.

Demo Code


//package com.java2s;
import java.util.Collections;
import java.util.HashSet;

import java.util.Set;

public class Main {
    /**//from   w  ww. j a v a 2s.  com
     * Turns a list of vararg parameters into a set.
     *
     * @param  ts  The vararg parameters.
     * @param  <T> The type of the parameters.
     *
     * @return A set created by adding the parameters in the order presented into a set.
     */
    public static <T> Set<T> paramsToSet(T... ts) {
        Set<T> result = new HashSet<>();

        Collections.addAll(result, ts);

        return result;
    }
}

Related Tutorials