List of usage examples for java.util HashSet HashSet
public HashSet(int initialCapacity)
From source file:Main.java
@SafeVarargs public static boolean equalsSize(List<? extends Object>... lists) { Set<Integer> sizes = new HashSet<Integer>(lists.length); for (List<? extends Object> list : lists) { if (list == null) { return false; }//from w ww . j a va2 s . co m if (sizes.isEmpty()) { sizes.add(list.size()); } else { if (sizes.add(list.size())) { return false; } } } return true; }
From source file:Main.java
public static Set<String> asSet(String... strs) { return new HashSet<String>(Arrays.asList(strs)); }
From source file:Main.java
public static Set<String> loadSet(SharedPreferences prefs, String setName) { final int size = prefs.getInt(setName + "_size", 0); Set<String> set = new HashSet<String>(size); for (int i = 0; i < size; i++) set.add(prefs.getString(setName + "_" + i, null)); return set;// w w w .j ava2 s.c o m }
From source file:Main.java
final static public Set<Object> synchronizedSet() { return Collections.synchronizedSet(new HashSet<Object>(INITIAL_CAPACITY)); }
From source file:Main.java
public static <T> Set<T> getReunionValues(Collection<? extends T> collectionA, Collection<? extends T> collectionB) { Set<T> newSet = new HashSet<T>(collectionA); newSet.addAll(collectionB);/* w ww . ja v a 2s.c om*/ return newSet; }
From source file:Main.java
public static <T> List<T> distinct(Collection<T> in) { if (in == null) { return new ArrayList<T>(); }/*from w ww. ja va 2 s .c om*/ return new ArrayList<T>(new HashSet<T>(in)); }
From source file:Main.java
/** * Interim method to get this code to compile against the 1.0-RC1 engine * @param key//from w ww . j a va 2 s . c o m * @param list * @return */ public static Set getSetFromList(List list) { return new HashSet(list); }
From source file:Main.java
public static boolean collectionsMatch(Collection<?> coll1, Collection<?> coll2) { if (coll1 == null && coll2 == null) { return true; } else if (coll1 != null && coll2 != null) { return new HashSet<>(coll1).equals(new HashSet<>(coll2)); } else {/*from ww w . j ava 2 s .c o m*/ return false; } }
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection removeDuplicates(Collection collection) { if (collection == null) return collection; Set duplicatesRemoved = new HashSet(collection); return duplicatesRemoved; }
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static boolean containsOnly(Collection collection, Object object) { if (collection == null) return false; Set duplicatesRemoved = new HashSet(collection); return duplicatesRemoved.size() == 1 && duplicatesRemoved.contains(object); }