import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class CreateUnmodifiableSet {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(set());
}
public static <T> Set<T> set(final T... elements) {
final HashSet<T> set = new HashSet<T>(elements.length);
Collections.addAll(set, elements);
return Collections.unmodifiableSet(set);
}
public static <T> Set<T> set() {
return new HashSet<T>();
}
/**
* @return an <b>UNMODIFIABLE</b> Set<T>
*/
public static <T> Set<T> unmodifiableSet(final Set<? extends T> s) {
return (s == null) ? Collections.<T> emptySet() : Collections
.unmodifiableSet(s);
}
}
Console:
[]