List of usage examples for java.util HashSet HashSet
public HashSet(int initialCapacity)
From source file:Main.java
public static Collection<? extends Object> getIntersection(Collection<? extends Object> list1, Collection<? extends Object> list2) { HashSet<?> hashSet = new HashSet<Object>(list1); Collection<?> intersection = hashSet; intersection.retainAll(list2);/* www.ja v a 2s .co m*/ return intersection; }
From source file:Main.java
/** * Returns the intersection of the given Collections. * * @param c1 the first Collection./*w ww . ja v a 2s .c o m*/ * @param c2 the second Collection. * @param <T> the type. * @return the intersection of the Collections. */ public static <T> Collection<T> intersection(Collection<T> c1, Collection<T> c2) { Set<T> set1 = new HashSet<>(c1); set1.retainAll(new HashSet<>(c2)); return set1; }
From source file:Main.java
public static <K> HashSet<K> createHashSet(int size) { return new HashSet<K>(size); }
From source file:Main.java
/** * Converts parameters into a set/*from www . ja va 2 s .c o m*/ * * @param <T> set element type * @param value element * @return set containing the given elements */ public static <T> Set<T> asSet(T value) { Set<T> set = new HashSet<>(1); set.add(value); return set; }
From source file:Main.java
final static public Set<Object> createSet(final Set<?> set) { return new HashSet<Object>(set); }
From source file:Main.java
/** * @param map map/* ww w. ja va2s . co m*/ * @return map deep copy */ public static Map<String, Set<String>> cloneMap(Map<String, Set<String>> map) { final Map<String, Set<String>> clone = new HashMap<>(map.size()); for (Map.Entry<String, Set<String>> entry : map.entrySet()) { final Set<String> cloneSet = new HashSet<>(entry.getValue()); clone.put(entry.getKey(), cloneSet); } return clone; }
From source file:Main.java
/** * Returns of set of the objects given in the vararg. * * @param contents the objects to return in the set. * @param <T> the class the given objects are instantiations of. * @return a set containing the given contents. * @throws AssertionError if any of the contents are not the same type. *///from w w w. java2s . co m public static <T> Set<T> setOf(T... contents) { return new HashSet<T>(listOf(contents)); }
From source file:Main.java
public static <A> Set<A> makeSet(Collection<A> xs) { if (xs.size() == 0) return Collections.<A>emptySet(); else if (xs.size() == 1) return Collections.singleton(xs.iterator().next()); else {// www .j a v a 2 s . co m Set<A> set = new HashSet<A>(xs.size()); set.addAll(xs); return set; } }
From source file:Main.java
/** * * * Create a set out of arguments. This is as close to an object literal as you can get in Java and very similar to * the scala Set()/*from www .j a v a 2 s .com*/ * * @param args items to put in a set * @param <T> type of set * @return set of items passed as arguments */ public static <T> Set<T> set(T... args) { return new HashSet<T>(Arrays.asList(args)); }
From source file:Main.java
public static <T> HashSet<T> newHashSet(int size) { return new HashSet<T>(getInitialCapacityFromExpectedSize(size)); }