Create unmodifiable Set from Array - Java java.util

Java examples for java.util:Set Creation

Description

Create unmodifiable Set from Array

Demo Code


//package com.java2s;
import java.util.Arrays;

import java.util.Collections;
import java.util.HashSet;

import java.util.Set;

public class Main {
    public static <T> Set<T> setOf(final T... items) {
        return Collections.unmodifiableSet(new HashSet<T>(Arrays
                .asList(items)));//from   w  w  w  .  j  ava2 s.  c  o  m
    }
}

Related Tutorials