Example usage for java.util HashSet add

List of usage examples for java.util HashSet add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:Main.java

@SafeVarargs
public static <T> HashSet<T> newHashSet(T... ts) {
    HashSet<T> set = new HashSet<>();
    for (T t : ts) {
        set.add(t);
    }/*from  www  . j  av  a 2  s  .  c  om*/
    return set;
}

From source file:Main.java

public static <T> HashSet<T> newHashSet(T... ts) {
    HashSet<T> set = new HashSet<T>();
    for (T t : ts) {
        set.add(t);
    }/*from w ww .ja v a2  s .co  m*/
    return set;
}

From source file:Main.java

@SafeVarargs
public static <T> HashSet<T> newHashSet(T... ts) {
    HashSet<T> set = new HashSet<T>();
    for (T t : ts) {
        set.add(t);
    }/*from  w w w  .j  ava  2  s .c o  m*/
    return set;
}

From source file:Main.java

static public <T> void unique(List<T> list) {
    HashSet<T> h = new HashSet<T>();
    for (T i : list) {
        h.add(i);
    }/*from  w  ww . j av a2 s.  co  m*/
    list.clear();
    for (T i : h) {
        list.add(i);
    }
}

From source file:Main.java

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

    for (T e : elements) {
        set.add(e);
    }//from  w  w  w.j  a  v a2 s.c  om
    return set;
}

From source file:Main.java

public static <T> Set<T> set(T... elements) {
    HashSet<T> ret = new HashSet<T>();
    for (T element : elements)
        ret.add(element);
    return ret;/*from   w  ww .j  av  a 2 s.  com*/
}

From source file:Main.java

/**
 * Create a new {@link HashSet} from an existing set and another element.
 *
 * @param existing/*from  w w  w .java  2  s .  c om*/
 * @param element
 * @return
 */
public static <T> HashSet<T> joinToHashSet(Set<T> existing, T element) {
    final HashSet<T> visitedWithNewPoint = new HashSet<T>(existing);

    visitedWithNewPoint.add(element);

    return visitedWithNewPoint;
}

From source file:Main.java

public static <T> boolean hasDuplicates(Collection<? extends T> xs) {
    HashSet<T> ys = new HashSet<>(xs.size());

    for (T x : xs)
        if (!ys.add(x))
            return true;

    return false;
}

From source file:Main.java

/**
 * Converts the typed Array into a typed HashSet
 * @param <T>//www  .  ja  va  2 s. c o m
 * @param tArray
 * @return
 */
public static <T> HashSet<T> asHashSet(T[] tArray) {
    HashSet<T> tSet = new HashSet<T>();
    for (T t : tArray) {
        tSet.add(t);
    }
    return tSet;
}

From source file:Main.java

/**
 * Return the hash set consisting of adding the specified argument
 * to a newly constructed set./*from   w  w  w.j a va  2s  .  c  om*/
 *
 * @param es Array of objects to add.
 * @return Hash set containing the argument elements.
 */
public static <E> HashSet<E> asSet(E... es) {
    HashSet<E> result = new HashSet<E>();
    for (E e : es)
        result.add(e);
    return result;
}