Example usage for java.util HashSet HashSet

List of usage examples for java.util HashSet HashSet

Introduction

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

Prototype

public HashSet(int initialCapacity) 

Source Link

Document

Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75).

Usage

From source file:Main.java

public static <T> Set<T> asSet(T... a) {
    return new HashSet<T>(Arrays.asList(a));
}

From source file:Main.java

/**
 * //w  ww  .j  a  va  2 s. c o m
 */
public static <T> Set<T> toSet(T... values) {
    // Precondition checking
    if (values == null) {
        return new HashSet<T>(0);
    }

    //
    Set<T> r = new HashSet<T>(values.length);
    for (T t : values) {
        r.add(t);
    }
    return r;
}

From source file:Main.java

/**
 * Remove all entries from collection a that are in collection b and returns a new collection.
 *//*  w  w  w  .  j a v  a 2  s.c o m*/
public static <T> Set<T> removeAll(Collection<T> a, Collection<T> b) {
    Set<T> c = new HashSet<T>(a);
    c.removeAll(b);
    return c;
}

From source file:Main.java

public static <T> Set<T> union(Set<T> set1, Set<T> set2) {
    if (set1 == null || set2 == null) {
        return (set1 == null) ? new HashSet<T>(set2) : new HashSet<T>(set1);
    }/*from w  w  w  .  ja  va2 s.  com*/
    Set<T> ret = new HashSet<T>(set1);
    ret.addAll(set2);
    return ret;
}

From source file:Main.java

public static <E, T extends Collection<E>> void removeDuplicates(T collection) {
    final Set<E> set = new HashSet<>(collection);
    collection.clear();/*from  w  ww.j  a v a 2 s .c o  m*/
    collection.addAll(set);
}

From source file:Main.java

public static <T> Set<T> makeSet(Collection<? extends T> a) {
    return new HashSet<T>(a);
}

From source file:Main.java

public static Set<Integer> getDelayedDeleteAlarms() {
    synchronized (delayedDeleteAlarms) {
        return new HashSet<>(delayedDeleteAlarms);
    }/*w  w w  .  j a  v a  2 s .co m*/
}

From source file:Main.java

@SafeVarargs
public static <T> Set<T> set(T... elements) {
    return new HashSet<T>(asList(elements));
}

From source file:Main.java

public static boolean containsDuplicates(Collection<?> coll) {
    if (coll == null)
        throw new IllegalArgumentException();

    Set<Object> set = new HashSet<>(coll);

    return set.size() != coll.size();
}

From source file:Main.java

public static synchronized Set<Object> getRegistered() {
    return new HashSet<Object>(events.keySet());
}