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() 

Source Link

Document

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

Usage

From source file:Main.java

public static <K, E> Set<E> getSetInitIfEmpty(Map<K, Set<E>> map, K key) {
    Set<E> value = map.get(key);
    if (value == null) {
        value = new HashSet<E>();
        map.put(key, value);/*from w  w w.j a  v  a  2 s  . com*/
    }
    return value;
}

From source file:Main.java

public static <T> Set<T> intersect(Collection<T> set1, Collection<T> set2) {
    HashSet<T> set = new HashSet<T>();

    for (T object : set1) {
        if (set2.contains(object)) {
            set.add(object);/*from  w  w  w.  j a v a  2  s .  c  o m*/
        }
    }

    return set;
}

From source file:Main.java

public static <T> Set<T> union(Collection<T> set1, Collection<T> set2) {
    HashSet<T> set = new HashSet<T>();

    for (T object : set1) {
        set.add(object);/*from   w  ww . j ava 2  s .com*/
    }
    for (T object : set2) {
        if (!set.contains(object)) {
            set.add(object);
        }
    }

    return set;
}

From source file:Main.java

public static Set<String> getAvailableIds() {
    Set<String> ids = new HashSet<>();
    ids.add(POOL1_NAME);//from w  w  w.  ja  v  a 2 s. com
    ids.add(POOL2_NAME);
    return ids;
}

From source file:Main.java

public static <T> Set<T> newSet(T... values) {
    Set<T> set = new HashSet<T>();
    for (T value : values) {
        set.add(value);/*from  w  ww  .j  a v  a  2  s.c  om*/
    }
    return set;
}

From source file:Main.java

public static <T> Set<T> union(Collection<? extends T> c1, Collection<? extends T> c2) {
    Set<T> result = new HashSet<T>();
    result.addAll(c1);/* w ww.  j a va2s  . c o m*/
    result.addAll(c2);
    return result;
}

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

/**
 * <p>/*w w  w. j a  v  a 2  s  .  com*/
 *    Creates an empty Set of Long types.
 * </p>
 * 
 * @return Set of Long types
 */
public static Set<Long> CreateEmptyLongSet() {
    return ((Set<Long>) (new HashSet<Long>()));
}

From source file:Main.java

public static <T> Set<T> newEmptySet() {
    return new HashSet<>();
}

From source file:Main.java

/**
 * Create new {@link HashSet}./* ww w .  j  ava 2  s  .  c  o m*/
 *
 * @param <K> key
 * @return {@link HashSet}
 */
public static <K> Set<K> newHashSet() {
    return new HashSet<K>();
}