List of usage examples for java.util Collection add
boolean add(E e);
From source file:com.talis.entity.TestUtils.java
public static Collection<Quad> getQuads(Node graph, Node subject, int num) { Collection<Quad> quads = new ArrayList<Quad>(); for (int i = 0; i < num; i++) { quads.add(new Quad(graph, subject, Node.createURI("http://example.com/p"), Node.createURI("http://example.com/o" + i))); }/*from ww w .j a v a 2s. c o m*/ return quads; }
From source file:Main.java
/** * Adds all elements in the array to the given collection. * * @param collection the collection to add to, may not be null * @param elements the array of elements to add, may not be null * @throws NullPointerException if the collection or array is null *///from ww w .ja v a2s . c o m public static <E, T extends E> void addAll(Collection<E> collection, T... elements) { for (int i = 0, size = elements.length; i < size; i++) { collection.add(elements[i]); } }
From source file:Main.java
/** * Adds all elements that a given {@link Iterator} provides to a given * {@link Collection} of appropriate type * /*from w w w . j a va2s . co m*/ * @param targetCollection * the {@link Collection} where to add the elements * @param sourceIterator * the {@link Iterator} where to get the elements from * @param <T> * the type of elements to transfer */ public static <T> void addAll(final Collection<? super T> targetCollection, final Iterator<? extends T> sourceIterator) { while (sourceIterator.hasNext()) { targetCollection.add(sourceIterator.next()); } }
From source file:Main.java
public static <E> boolean addNotNullElement(Collection<E> c, E e) { if (!isNotNull(c)) { return false; }/* w w w . j a v a2 s. c o m*/ if (e == null) { return false; } c.add(e); return true; }
From source file:Main.java
/** * Adds the contents of an iterator to an existing Collection. * @param <T> The type of elements returned by the iterator. * @param collection The receptacle to put the elements into. * @param elementsToAdd The elements to add to the Collection. *//* w ww .jav a 2s.co m*/ public static <T> void addToCollection(Collection<T> collection, Iterator<T> elementsToAdd) { while (elementsToAdd.hasNext()) { T next = elementsToAdd.next(); collection.add(next); } }
From source file:Main.java
public static String toString(String separator, Object... objects) { Collection<Object> objectsCol = new ArrayList<Object>(objects.length); for (Object obj : objects) { objectsCol.add(obj); }//from w ww .j av a 2 s . c om return toString(objectsCol, null, separator, null); }
From source file:Main.java
public final static <T> void Append(Collection<T> collection, T[] array) { if (collection != null && array != null && array.length > 0) { for (T element : array) { collection.add(element); }/* w ww . j a va2 s .c om*/ } }
From source file:Main.java
public static <T> Collection<T> copy(Collection<T> col, T... arr) { if (col == null) { col = new ArrayList<T>(arr.length); }//w w w . jav a 2 s.c om for (T t : arr) { col.add(t); } return col; }
From source file:edu.harvard.med.screensaver.util.CollectionUtils.java
public static <T> void fill(Collection<T> c, T e, int i) { for (; i > 0; i--) { c.add(e); }//from ww w. j a va2 s. c o m }
From source file:Main.java
/** * Adds all elements in the enumeration to the given collection. * @deprecated Replaced by {@link Collection#addAll(java.util.Collection<? extends E>)} * * @param collection the collection to add to * @param enumeration the enumeration of elements to add, may not be null * @throws NullPointerException if the collection or enumeration is null *///from w w w.j av a 2 s . c o m public static <E> void addAll(Collection<E> collection, Enumeration<? extends E> enumeration) { while (enumeration.hasMoreElements()) { collection.add(enumeration.nextElement()); } }