List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:Main.java
/** * Creates a new {@link Set} with the inferred type * using the given elements.//from w w w. j av a 2 s . co m */ public static <T> Set<T> set(T... vals) { HashSet<T> ret = new HashSet<T>(); for (T v : vals) ret.add(v); return ret; }
From source file:Main.java
/** * Convert the given array into a {@link Set}. Changes to elements in the * set "write through" to the original array. * * @param array The array to convert or <code>null</code> for none. * @return Returns a new {@link Set} or <code>null</code> if * <code>null</code> was given for the array argument. *//* w w w. jav a2 s . co m*/ public static <T> Set<T> asSet(T[] array) { if (array == null) return null; final HashSet<T> set = new HashSet<T>(); for (T element : array) set.add(element); return set; }
From source file:Main.java
public static <T> Set<T> union(Collection<T> set1, Collection<T> set2) { HashSet<T> set = new HashSet<T>(); for (T object : set1) { set.add(object); }/*from ww w . ja v a2s . c om*/ for (T object : set2) { if (!set.contains(object)) { set.add(object); } } return set; }
From source file:Main.java
public static ArrayList<Node> getNodesWithKey(Node parent, String key, String value, boolean all_of_them) { HashSet<String> values = new HashSet<String>(); values.add(value); return getNodesWithKey(parent, key, values, all_of_them); }
From source file:Main.java
public static <T> HashSet<T> asHashSet(T... elements) { HashSet<T> result = new HashSet<T>(); for (T elem : elements) { result.add(elem); }//from w w w .j av a 2 s .com return result; }
From source file:Main.java
public static <T> Set<T> newSet(T... theValues) { HashSet<T> retVal = new HashSet<T>(); for (T t : theValues) { retVal.add(t); }//from w w w . j a v a2s . com return retVal; }
From source file:Main.java
public static Node getNodeWithKey(Node parent, String key, String value) { HashSet<String> values = new HashSet<String>(); values.add(value); ArrayList<Node> nodes = getNodesWithKey(parent, key, values, false); if (nodes.size() < 1) return null; return nodes.get(0); }
From source file:Main.java
public static HashSet<String> stringSet(String... strings) { HashSet<String> set = new HashSet<String>(); for (String s : strings) set.add(s); return set;//from w ww . j a v a2 s . co m }
From source file:Main.java
public static List<Node> getNodesWithKey(Node parent, String key, String value, boolean all_of_them) { HashSet<String> values = new HashSet<>(); values.add(value); return getNodesWithKey(parent, key, values, all_of_them); }
From source file:Main.java
/** * Creates a new list with the given elements * @param values// ww w.ja v a 2 s.c om * @return */ @SafeVarargs public static <T> Set<T> newSet(T... values) { HashSet<T> set = new HashSet<>(values.length); for (T element : values) { set.add(element); } return set; }