Create an unmodifiable Set - Java java.util

Java examples for java.util:Set Creation

Description

Create an unmodifiable Set

Demo Code


//package com.java2s;

import java.util.Collections;

import java.util.Set;

public class Main {
    /**/*from w  w  w  .  jav  a  2s . co  m*/
     * @return an <b>UNMODIFIABLE</b> Set&lt;T&gt;
     */
    public static <T> Set<T> unmodifiableSet(final Set<? extends T> s) {
        return (s == null) ? Collections.<T> emptySet() : Collections
                .unmodifiableSet(s);
    }
}

Related Tutorials