List of usage examples for java.util Set addAll
boolean addAll(Collection<? extends E> c);
From source file:Main.java
public static <T> Set<T> union(Set<T> set1, Set<T> set2) { if (set1 == null || set2 == null) { return (set1 == null) ? new HashSet<T>(set2) : new HashSet<T>(set1); }//from w ww .j a va2 s . c om Set<T> ret = new HashSet<T>(set1); ret.addAll(set2); return ret; }
From source file:Main.java
/** * This method finds the union of set A and set B * @param setA set A/*from w w w . j a v a2 s. co m*/ * @param setB set B * @param <T> type * @return a new set containing the union */ public static <T> Set<T> union(Set<T> setA, Set<T> setB) { Set<T> union = new HashSet<T>(setA); union.addAll(setB); return union; }
From source file:Main.java
public static <T> Set<T> createSetContaining(T... contents) { Set<T> contentsAsSet = new HashSet<T>(); contentsAsSet.addAll(Arrays.asList(contents)); return contentsAsSet; }
From source file:Main.java
/** * Returns the difference of two sets (S1\S2). It calls {@link Set#removeAll(java.util.Collection)} but returns a * new set containing the elements of the difference. * /*w w w. j av a 2 s. c om*/ * @param set1 * the first set * @param set2 * the second set * @return the difference of the sets */ public static <V> Set<V> difference(Set<V> set1, Set<V> set2) { Set<V> difference = new HashSet<V>(); difference.addAll(set1); difference.removeAll(set2); return difference; }
From source file:Main.java
public static <T> Set<T> clone(Set<T> set) { Set<T> clone = new HashSet<T>(); clone.addAll(set); return clone; }
From source file:Main.java
public static <T> Collection<T> union(final Collection<T> collection1, final Collection<T> collection2) { final Set<T> set = new HashSet<T>(collection1); set.addAll(collection2); return set;//from ww w .ja v a2 s . c o m }
From source file:Set2.java
public static void test(Set a) { fill(a, 10);// ww w .ja v a 2 s. c o m fill(a, 10); // Try to add duplicates fill(a, 10); a.addAll(fill(new TreeSet(), 10)); System.out.println(a); }
From source file:Main.java
/** * Makes an union between both of the given lists.<br/> * The result contains unique values.// w ww .j a v a 2 s.c om * @param list1 the first list. * @param list2 the second list. * @param <T> * @return the union between the two lists. */ public static <T> List<T> union(List<T> list1, List<T> list2) { Set<T> set = new LinkedHashSet<T>(); set.addAll(list1); set.addAll(list2); return new ArrayList<T>(set); }
From source file:Main.java
public static <E> Set<E> treeSet(Set<E> base, E... add) { Set<E> result = new TreeSet<>(); result.addAll(base); if (add != null) { result.addAll(Arrays.asList(add)); }/* ww w. j av a 2 s . c o m*/ return result; }
From source file:Main.java
public static <T> Set<T> unicon(Set<T> set1, Set<T> set2) { Set<T> set = new HashSet<>(); set = set1;/*from w w w.ja va2 s. c o m*/ set.addAll(set2); return set; }