Example usage for java.util Set add

List of usage examples for java.util Set add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:Main.java

public static <T> void setAddAll(Set<T> set, T[] array) {
    for (T t : array)
        set.add(t);
}

From source file:Main.java

private static Set<Integer> checkDuplicate(int[] intArray) {
    Set<Integer> duplicates = new HashSet<Integer>();
    Set<Integer> tmp = new HashSet<Integer>();
    for (Integer i : intArray) {
        if (!tmp.add(i)) {
            duplicates.add(i);// w w  w . j  ava2 s.  c  o m
        }
    }
    return duplicates;
}

From source file:Main.java

public static Set<String> getExpectedDoorNames() {
    Set<String> expectedDoors = new HashSet<>();
    expectedDoors.add(DOOR1_NAME);
    expectedDoors.add(DOOR2_NAME);/*from w  w  w  . ja  va  2s  .c  o m*/
    expectedDoors.add(DOOR3_NAME);
    return expectedDoors;
}

From source file:Main.java

public static <K, V> void addToMap(K key, V value, Map<K, Set<V>> map) {

    if (key != null && value != null)
        if (map.containsKey(key))
            map.get(key).add(value);/*from  w  ww . j  a  v  a2  s.c o  m*/
        else {
            Set<V> values = new TreeSet<V>();
            values.add(value);
            map.put(key, values);
        }
}

From source file:Main.java

public static <K, V> boolean add(Map<K, Set<V>> map, K key, V value) {
    Set<V> set = getSet(map, key);
    return set.add(value);
}

From source file:Main.java

public static <T> void arrayToSet(Set<T> set, T[] array) {
    for (T t : array) {
        set.add(t);
    }
}

From source file:Main.java

public static <T> Set<T> toSet(T... arr) {
    Set<T> set = new HashSet<T>();
    for (T t : arr)
        set.add(t);
    return set;//from   w w  w. j  a v a 2s  . c  o  m
}

From source file:Main.java

public static Map<Integer, Set<Class<?>>> simpleParameterClasses(final Class<?>... classes) {
    final Map<Integer, Set<Class<?>>> res = new HashMap<>(classes.length);
    for (int i = 0; i < classes.length; i++) {
        final Set<Class<?>> set = new HashSet<>(1);
        set.add(classes[i]);
        res.put(i, set);/*from w w  w .ja v a 2s .  c om*/
    }
    return res;
}

From source file:Main.java

public static void filterSets() {
    Set<String> words = new HashSet<>();
    words.add("1");
    words.add("2");
    words.add("3");
    Set<String> filteredSet = Sets.filter(words, new Predicate<String>() {
        @Override//from ww  w.j a  v a 2s.c om
        public boolean apply(String input) {
            return input.equals("1");
        }
    });

    System.out.println(Iterables.toString(filteredSet));

}

From source file:Main.java

public static Set setWith(Object firstElement, Object secondElement, Object thirdElement) {
    Set set = setWith(firstElement, secondElement);
    set.add(thirdElement);
    return set;//from   w ww.j a  v  a2 s .  co m
}