List of usage examples for java.util HashSet HashSet
public HashSet(int initialCapacity)
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()/*w w w .j a v a 2s. c o m*/ * * @param targetCollection items to put in a set * @param <T> type of set * @return set of items passed as arguments */ public static <T> Set<T> setFrom(Collection<T> targetCollection) { return new HashSet<T>(targetCollection); }
From source file:Main.java
private static String[] convertCursorAsStringArrayWithCloseCursor(Cursor cursor, int colIdx) { String[] result = null;// ww w . j a v a2 s .c om try { int resultCount = cursor.getCount(); if (resultCount > 0) { HashSet<String> phones = new HashSet<String>(resultCount); while (cursor.moveToNext()) { String phone = cursor.getString(0); phones.add(phone); } result = phones.toArray(new String[phones.size()]); } Log.d(TAG, "ConvertCursor As StringArray : found " + resultCount + " String converted from idx " + colIdx); } finally { cursor.close(); } return result; }
From source file:Main.java
public static <T> Set<T> toSet(Collection<T> c) { if (isEmpty(c)) { return new HashSet<>(0); }//from w w w .ja v a2 s .c o m return new HashSet<>(c); }
From source file:Main.java
/** * Function to check if duplication elements are present in array or not. * @param contacts array of string//from w w w .j a v a 2 s . co m * @return true if duplication is present else return false. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static boolean isDuplicatePresent(String[] contacts) { List inputList = Arrays.asList(contacts); Set inputSet = new HashSet(inputList); if (inputSet.size() < inputList.size()) return true; return false; }
From source file:Main.java
/** * /*from w w w . j a v a2 s .co m*/ * Turns a column of the resultset's value into Set * * @param results * @param key * key to get the value from the result set * @return null if results is null */ public static Set<String> turnMapResultToSet(List<? extends Map<?, ?>> results, String key) { if (results == null) return null; Set<String> set = new HashSet<String>(results.size()); for (Map<?, ?> map : results) { set.add((String) map.get(key)); } return set; }
From source file:Main.java
public static <Element_Type> Set<Element_Type> hashSetFrom(Element_Type... elements) { return new HashSet<Element_Type>(Arrays.asList(elements)); }