Java Collection Add addAll(Collection c, T... array)

Here you can find the source of addAll(Collection c, T... array)

Description

Adds objects in array to the given collection

License

Apache License

Parameter

Parameter Description
c collection to which add each element of array.
array ~ items

Return

the same collection which is passed as argument

Declaration

public static <E, T extends E> Collection<E> addAll(Collection<E> c, T... array) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

import java.util.List;

public class Main {
    /**//w ww  .  j a va2s.  com
     * Adds objects in array to the given collection
     * 
     * @param c
     *            collection to which add each element of array.
     * @param array
     *            ~ items
     * @return the same collection which is passed as argument
     */
    public static <E, T extends E> Collection<E> addAll(Collection<E> c, T... array) {
        for (T obj : array) {
            c.add(obj);
        }
        return c;
    }

    /**
     * Adds the given item to the list at specified <code>index</code>.
     * <p/>
     * if <code>index</code> is greater than list size, it simply appends to the
     * list.
     * 
     * @param list
     *            collection of elements
     * @param index
     *            specific index
     * @param item
     *            object to add.
     */
    public static <E, T extends E> void add(List<E> list, int index, T item) {
        if (index < list.size()) {
            list.add(index, item);
        } else {
            list.add(item);
        }
    }
}

Related

  1. addAll(Collection col, Iterable iterable)
  2. addAll(Collection collection, Iterable toAdd)
  3. addAll(Collection addTo, Iterable elementsToAdd)
  4. addAll(Collection c, Iterable elts)
  5. addAll(Collection c, T... array)
  6. addAll(Collection coll, Iterable it)
  7. addAll(Collection collection, E... args)
  8. addAll(Collection collection, Iterable iterable)
  9. addAll(Collection collection, Iterator iterator)