List of usage examples for java.util Collection add
boolean add(E e);
From source file:Main.java
private static <T> void addToCollection(Collection<T> theCollection, T... objects) { for (T object : objects) { theCollection.add(object); }//from w w w . ja v a2 s . c om }
From source file:Main.java
public static <T> Collection<T> merge(Collection<T> c1, Collection<T> c2) { for (T e : c2) { if (!c1.contains(e)) { c1.add(e); }/*from w ww. jav a 2 s .c o m*/ } return c1; }
From source file:Main.java
/** * Adds all elements in the iteration to the given collection. * //from w ww . j av a 2 s . com * @param collection the collection to add to, must not be null * @param iterator the iterator of elements to add, must not be null * @throws NullPointerException if the collection or iterator is null */ public static <T> void addAll(Collection<T> collection, Iterator<T> iterator) { while (iterator.hasNext()) { collection.add(iterator.next()); } }
From source file:Main.java
public static void addAll(Collection collection, Object[] array) { for (int i = 0, max = array.length; i < max; i++) { collection.add(array[i]); }//from w w w. j ava2 s .c o m }
From source file:Main.java
public static <T> void addIfNotNullNotExist(Collection<T> col, T val) { if (val != null && !col.contains(val)) { col.add(val); }/*from w w w. ja v a 2 s. c o m*/ }
From source file:Main.java
/** * Used for dividing an original list into two lists. * /*from w w w . jav a 2 s. co m*/ * @param <T> * @param list * @param i * @return */ public static <O, P extends O> boolean safeAddAll(Collection<O> c, P[] items) { try { for (O item : items) { c.add(item); } return true; } catch (Throwable ex) { return false; } }
From source file:Main.java
public static <T> void addAll(Collection<T> c, Iterable<? extends T> i) { for (T t : i) { c.add(t); }/*from ww w.j ava 2 s . c o m*/ }
From source file:Main.java
public static Collection<Node> search_nodes_by_name(Node root, String name) { Collection<Node> result = new LinkedList<Node>(); if (root.getNodeName().equals(name)) result.add(root); NodeList list = root.getChildNodes(); for (int i = 0; i < list.getLength(); ++i) { Node child = list.item(i); Collection<Node> ret = search_nodes_by_name(child, name); result.addAll(ret);//from w w w . j a va2 s .c o m } return result; }
From source file:Main.java
/** * Filters the src collection and puts the objects matching the * clazz into the dest collection.//from ww w. j a v a 2 s .c o m */ public static <T> void filter(Class<T> clazz, Collection<?> src, Collection<T> dest) { for (Object o : src) { if (clazz.isInstance(o)) { dest.add(clazz.cast(o)); } } }
From source file:Main.java
public static boolean add(Collection collection, Object object) { if (collection == null || object == null) return false; collection.add(object); return true;/*w w w . j av a2 s .c o m*/ }