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 <T> Set<T> union(Set<T> set1, Set<T> set2) {
    Set<T> set = new HashSet<>();
    set.addAll(set1);//from   w w  w.  j  av  a2s.  c o m
    set.addAll(set2);
    return set;
}

From source file:Main.java

public static HashSet<String> stringToHashSet(String str) {
    HashSet<String> hs = new HashSet<String>();
    if (str.equals("") || str == null)
        return null;
    if (!str.contains(","))
        hs.add(str);/*w ww . j a  va2s .c  om*/
    else {
        String[] arr = str.split(",");
        for (String s : arr)
            hs.add(s);
    }
    return hs;

}

From source file:Main.java

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

From source file:Main.java

@SafeVarargs
public static <T> Set<T> set(T... objects) {
    Set<T> set = new HashSet<>();
    for (T t : objects) {
        set.add(t);/* ww  w  .  ja  va2 s .  c  om*/
    }
    return set;
}

From source file:Main.java

public static <T> Set<T> asSet(T... elements) {
    Set<T> toReturn = new HashSet<>();
    toReturn.addAll(Arrays.asList(elements));
    return toReturn;
}

From source file:Main.java

public static <T> Set<T> asSet(T... array) {
    Set<T> result = new HashSet<>();
    result.addAll(Arrays.asList(array));
    return result;
}

From source file:Main.java

public static final <T> Set<T> setOf(final T... elements) {
    final Set<T> set = new HashSet<T>();

    for (final T t : elements) {
        set.add(t);/*from   www . ja  v a2s . c  om*/
    }

    return set;
}

From source file:Main.java

public static Set setWith(Object anElement) {
    Set asSet = new HashSet();
    asSet.add(anElement);
    return asSet;
}

From source file:Main.java

public static Set<Integer> closedRange(int start, int end) {
    Set<Integer> range = new HashSet<Integer>();
    for (int i = start; i <= end; i++) {
        range.add(i);/* w w  w  .  java 2  s.c o m*/
    }
    return range;
}

From source file:Main.java

private static Set<Class<?>> getWrapperTypes() {
    Set<Class<?>> ret = new HashSet<Class<?>>();
    ret.add(Boolean.class);
    ret.add(Character.class);
    ret.add(Byte.class);
    ret.add(Short.class);
    ret.add(Integer.class);
    ret.add(Long.class);
    ret.add(Float.class);
    ret.add(Double.class);
    ret.add(Void.class);
    ret.add(String.class);
    return ret;/*  w  ww .  j  a v a 2 s . c o  m*/
}