List of usage examples for java.util HashSet HashSet
public HashSet(int initialCapacity)
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void removeDuplicate(ArrayList arlList) { HashSet h = new HashSet(arlList); arlList.clear();/* w w w.j a v a 2s . com*/ arlList.addAll(h); }
From source file:Main.java
public static List<String> removeDuplicate(List<String> list) { HashSet<String> hashSet = new HashSet<String>(list); list.clear();// w w w.j a v a 2 s. c o m list.addAll(hashSet); return list; }
From source file:Main.java
public static <T> Set<T> intersect(Collection<? extends T> a, Collection<? extends T> b) { Set<T> intersection = new HashSet<T>(a); intersection.retainAll(b);/* w ww. j a v a 2s .co m*/ return intersection; }
From source file:Main.java
public static <T> List<T> mergeLists(List<T> oldList, List<T> newList) { //TreeSet setBoth = new TreeSet(newList); HashSet<T> setBoth = new HashSet<>(newList); setBoth.addAll(oldList);/*from w ww.ja v a 2s.com*/ oldList.clear(); oldList.addAll(setBoth); return oldList; }
From source file:Main.java
public static <E> HashSet<E> newHashSet(E... elements) { HashSet<E> set = new HashSet<E>(elements.length); Collections.addAll(set, elements); return set;// w ww. j a v a 2s . c o m }
From source file:Main.java
public static <E> Set<E> union(final Set<E> set1, final Set<E> set2) { Set<E> set = new HashSet<>(set1); set.addAll(set2);//from w w w. j av a 2 s . c o m return Collections.unmodifiableSet(set); }
From source file:Main.java
public static <T> Set<T> intersect(Collection<T> l1, Collection<T> l2) { Set<T> nl = new HashSet<T>(l1); nl.retainAll(l2);//www . j av a2 s .c o m return nl; }
From source file:Main.java
public static <T> Set<T> difference(Collection<T> s1, Collection<T> s2) { Set<T> ns = new HashSet<T>(s1); ns.removeAll(s2);/*from w ww . j ava 2 s . co m*/ return ns; }
From source file:Main.java
public static <E> Set<E> difference(final Set<E> set1, final Set<E> set2) { Set<E> set = new HashSet<>(set1); set.removeAll(set2);/* w w w. ja v a 2s. c o m*/ return Collections.unmodifiableSet(set); }
From source file:Main.java
public static <E> Set<E> intersection(final Set<E> set1, final Set<E> set2) { Set<E> set = new HashSet<>(set1); set.retainAll(set2);//ww w . j a va 2 s. co m return Collections.unmodifiableSet(set); }