List of usage examples for java.util HashSet HashSet
public HashSet()
From source file:Main.java
private static Set<String> getRedSet(Set<Integer> numSet) { Set<String> redSet = new HashSet<String>(); // add single Num Set<String> headSet = getHeadSet(numSet); for (Integer singleNum : numSet) { if (singleNum == 0) continue; redSet.add("" + singleNum); }/*from www . j av a 2 s .c o m*/ for (String head : headSet) { for (Integer tail : numSet) { if (head.equals("3") && tail > 3) continue; redSet.add(head + tail); } } return redSet; }
From source file:Main.java
public static <T> Set<T> intersect(Set<T> sourceSet, Set<T> targetSet) { Set<T> set = new HashSet<T>(); int sourceSetSize = sourceSet.size(); int targetSetSize = targetSet.size(); Set<T> minSet = null;//from w w w .j ava 2 s. com Set<T> maxSet = null; if (sourceSetSize <= targetSetSize) { minSet = sourceSet; maxSet = targetSet; } else { minSet = targetSet; maxSet = sourceSet; } for (T t : minSet) { if (maxSet.contains(t)) { set.add(t); } } return set; }
From source file:Main.java
public static <K> Set<K> intersect(Collection<K> a, Collection<K> b) { Set<K> ret = new HashSet<K>(); for (K v : a) { if (b.contains(v)) ret.add(v);//from w ww. j a v a2 s . co m } return ret; }
From source file:Main.java
public static <E> Set<E> toSet(Iterable<? extends E> iterable) { final Set<E> set = new HashSet<E>(); for (E e : iterable) { set.add(e);/*from w w w. jav a2 s . c om*/ } return Collections.unmodifiableSet(set); }
From source file:Main.java
public static <A> Set<A> setIntersection(Set<A> a, Set<A> b) { Set<A> set = new HashSet<A>(); for (A x : a) if (b.contains(x)) set.add(x);/* ww w.ja v a 2 s . c om*/ return set; }
From source file:Main.java
public static <T> Set<T> makeSet() { return new HashSet<T>(); }
From source file:Main.java
public static <T> Set<T> toUniqueSet(T[] array) { HashSet<T> set = new HashSet<T>(); if (array != null) { for (T object : array) { if (!set.contains(object)) { set.add(object);//from w ww .ja v a 2s.c o m } } } return set; }
From source file:Main.java
public final static Set<String> getMethods(Class<?> clazz) { HashSet<String> methodSet = new HashSet<String>(); Method[] methodArray = clazz.getMethods(); for (Method method : methodArray) { String methodName = method.getName(); methodSet.add(methodName);// w w w . j a v a 2 s .c o m } return methodSet; }
From source file:Main.java
public static <T extends Comparable<T>> Set<T> getDuplicates(List<T> list) { List<T> sortedList = getSortedList(list); Set<T> duplicates = new HashSet<>(); for (int index = 1; index < sortedList.size(); index++) { T previousElement = sortedList.get(index - 1); T currentElement = sortedList.get(index); if (currentElement.equals(previousElement)) { duplicates.add(currentElement); }/*from w w w .j ava 2 s . com*/ } return duplicates; }
From source file:Main.java
public static <E> Set<E> toSet(Iterable<E> iterable) { if (iterable instanceof Set) { return (Set<E>) iterable; }/*from w ww. j av a 2 s .c om*/ Set<E> set = new HashSet<>(); if (iterable != null) { for (E e : iterable) { set.add(e); } } return set; }