Returns the items as a populated set. - Java java.util

Java examples for java.util:Set Operation

Description

Returns the items as a populated set.

Demo Code


//package com.java2s;

import java.util.HashSet;

import java.util.Set;

public class Main {
    /**//ww  w .ja  va  2  s  . c o m
     * Returns the items as a populated set.
     * 
     * @param items Object[]
     * @return Set
     */
    public static <T> Set<T> asSet(T[] items) {

        Set<T> set = new HashSet<T>(items.length);
        for (int i = 0; i < items.length; i++) {
            set.add(items[i]);
        }
        return set;
    }
}

Related Tutorials