Example usage for java.util Collections unmodifiableSet

List of usage examples for java.util Collections unmodifiableSet

Introduction

In this page you can find the example usage for java.util Collections unmodifiableSet.

Prototype

public static <T> Set<T> unmodifiableSet(Set<? extends T> s) 

Source Link

Document

Returns an unmodifiable view of the specified set.

Usage

From source file:MainClass.java

public static void main(String[] a) {
    Set s = new HashSet();
    s.add("A");/*from   ww  w.j  a  v  a2s .  com*/
    s.add("B");
    s.add("C");
    s.add("D");
    s.add("E");
    s.add("F");
    s.add("H");

    Collections.unmodifiableSet(s);

    s = Collections.unmodifiableSet(s);

    s.clear();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    List stuff = Arrays.asList(new String[] { "a", "b" });

    List list = new ArrayList(stuff);
    list = Collections.unmodifiableList(list);

    try {/*from w w  w .  j  ava2  s  .  co  m*/
        list.set(0, "new value");
    } catch (UnsupportedOperationException e) {

    }

    Set set = new HashSet(stuff);
    set = Collections.unmodifiableSet(set);

    Map map = new HashMap();
    map = Collections.unmodifiableMap(map);
}

From source file:Main.java

public static <K> Set<K> createUnmodifiableSet(Set<K> ks) {
    return Collections.unmodifiableSet(ks);
}

From source file:Main.java

public static <T> Set<T> unmodifiableSetOrNull(Set<? extends T> a_set)
/*     */ {//from  w w w  . j a  va2  s  .  co  m
    /* 286 */return a_set == null ? null : Collections.unmodifiableSet(a_set);
    /*     */}

From source file:Main.java

@SafeVarargs
public static <V> Set<V> unmodifiableSet(V... elements) {
    return Collections.unmodifiableSet(toSet(new HashSet<V>(), elements));
}

From source file:Main.java

public static <T> Set<T> unmodifiableSet(Set<? extends T> set) {
    if (set == null) {
        return Collections.emptySet();
    } else {/*w w  w .  j  a  va2s  . c o m*/
        return Collections.unmodifiableSet(set);
    }
}

From source file:Main.java

public static <T> Set<T> unmodifiableSet(Set<T> orig) {
    return Collections.unmodifiableSet(orig);
}

From source file:Main.java

public static <E> Set<E> union(final Set<E> set1, final Set<E> set2) {
    Set<E> set = new HashSet<>(set1);
    set.addAll(set2);/* ww w.j av a 2s.  co m*/
    return Collections.unmodifiableSet(set);
}

From source file:Main.java

public static <E> Set<E> toSet(Iterable<? extends E> iterable) {
    final Set<E> set = new HashSet<E>();

    for (E e : iterable) {
        set.add(e);//  ww w.j  av a  2  s.com
    }

    return Collections.unmodifiableSet(set);
}

From source file:Main.java

public static <E> Set<E> difference(final Set<E> set1, final Set<E> set2) {
    Set<E> set = new HashSet<>(set1);
    set.removeAll(set2);//from  w  ww .j a va2 s. co m
    return Collections.unmodifiableSet(set);
}