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 Set<Character> arrayToSet(char[] array) {
    Set<Character> arraySet = new HashSet<Character>();
    for (Character character : arraySet) {
        arraySet.add(character);/*from w  w  w.  j av  a 2s. c om*/
    }
    return arraySet;
}

From source file:Main.java

public static <E> Set<E> union(Set<? extends E> x, Set<? extends E> y) {
    Set<E> union = new HashSet<E>();
    union.addAll(x);//from  w w  w . j  a  v  a2  s  . co  m
    union.addAll(y);
    return union;
}

From source file:Main.java

public static <T> Set<T> newHashSet(final T... ts) {

    final Set<T> resultSet = new HashSet<T>();
    if (ts == null) {
        return new HashSet<T>();
    } else {/*from w  ww .  j  av a2 s. c o  m*/

        for (final T t : ts) {
            resultSet.add(t);
        }
    }

    return resultSet;
}

From source file:Main.java

public static String[] union(String[] arr1, String[] arr2) {
    Set<String> set = new HashSet<>();
    for (String str : arr1) {
        set.add(str);//from w ww.  j a  v a  2s  .  co m
    }
    for (String str : arr2) {
        set.add(str);
    }
    String[] result = {};
    return set.toArray(result);
}

From source file:Main.java

public static Set<Integer> randomSetRange(int min, int max, int n) {
    Set<Integer> set = new HashSet<Integer>();
    while (set.size() < n) {
        int num = (int) (Math.random() * (max - min)) + min;
        set.add(num);/*www  . ja  v  a2 s  .  co  m*/
    }
    return set;

}

From source file:Main.java

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

From source file:Main.java

private static Set<String> getBlueSet(Set<Integer> numSet) {
    Set<String> blueSet = new HashSet<String>();
    for (Integer i : numSet) {
        if (i < 10 && i > 0) {
            blueSet.add("" + i);
        }/* w  ww.j  a  v a 2s .co m*/

        if (i < 7 && i > 0) {
            blueSet.add("1" + i);
        }
    }

    return blueSet;
}

From source file:Main.java

public static <T> Set<T> arrayToSet(T[] array) {
    if (array == null) {
        return new HashSet<T>();
    }//from  w  ww .  j a va 2s.  co m
    Set<T> set = new HashSet<T>();
    for (T t : array) {
        set.add(t);
    }
    return set;
}

From source file:Main.java

public static <T> Set<T> asSet(T... obj) {
    Set<T> set = new HashSet<T>();
    for (T el : obj) {
        set.add(el);// www .  j a v  a  2 s .c o  m
    }
    return set;
}

From source file:Main.java

public static <T> Set<T> asSet(T... arr) {
    Set<T> ret = new HashSet<T>();
    for (T t : arr) {
        ret.add(t);/*ww w  . ja v  a2s. com*/
    }
    return ret;
}