Java Utililty Methods Collection Add

List of utility methods to do Collection Add

Description

The list of methods to do Collection Add are organized into topic(s).

Method

voidaddAll(Collection collection, Iterable iterable)
add All
addAll(collection, iterable.iterator());
voidaddAll(Collection collection, Iterator iterator)
Adds all elements in the iteration to the given collection.
while (iterator.hasNext()) {
    collection.add(iterator.next());
voidaddAll(Collection pCollection, Iterator pIterator)
Adds all elements of the iterator to the collection.
while (pIterator.hasNext()) {
    pCollection.add(pIterator.next());
voidaddAll(Collection integerCollection, int[] intArray)
Adds an array of integer values to a collection of Integer
for (int iValue : intArray) {
    integerCollection.add(iValue);
voidaddAll(Collection c, T[] a)
INTERNAL: Adds all elements in the array to the collection.
for (int i = 0; i < a.length; i++) {
    c.add(a[i]);
voidaddAll(Collection col, T[] arr)
add All
if (isEmpty(arr)) {
    return;
for (T val : arr) {
    col.add(val);
voidaddAll(Collection coll, T... elems)
Appends an arbitrary number of explicit elements to an existing collection.
for (T elem : elems)
    coll.add(elem);
CaddAll(Collection coll1, Collection coll2)
A potentially more efficient addAll() for unordered Collections.
if (coll1 == null)
    return (C) coll2;
if (coll2 == null)
    return (C) coll1;
Collection<T> cSmaller, cBigger;
if (coll1.size() < coll2.size()) {
    cSmaller = coll1;
    cBigger = coll2;
...
booleanaddAll(Collection collection, Collection toAdd)
add All
int size = toAdd.size();
boolean result = false;
if (size > 0) {
    if (size < 10)
        for (T element : toAdd)
            result |= collection.add(element);
    else
        result = collection.addAll(toAdd);
...
voidaddAll(Collection collection, Iterable items)
Add all the items from an iterable to a collection.
for (T item : items) {
    collection.add(item);