Java Collection Add addAll(Collection collection, Iterator iterator)

Here you can find the source of addAll(Collection collection, Iterator iterator)

Description

Adds all elements in the iteration to the given collection.

License

Open Source License

Parameter

Parameter Description
collection the collection to add to
iterator the iterator of elements to add, may not be null

Exception

Parameter Description
NullPointerException if the collection or iterator is null

Declaration

public static void addAll(Collection collection, Iterator iterator) 

Method Source Code

//package com.java2s;
/*//  w ww  .j av  a  2 s  .c  om
 * Copyright (c) 2007-2016 AREasy Runtime
 *
 * This library, AREasy Runtime and API for BMC Remedy AR System, is free software ("Licensed Software");
 * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT,
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 */

import java.util.*;

public class Main {
    /**
     * Adds all elements in the iteration to the given collection.
     *
     * @param collection the collection to add to
     * @param iterator   the iterator of elements to add, may not be null
     * @throws NullPointerException if the collection or iterator is null
     */
    public static void addAll(Collection collection, Iterator iterator) {
        while (iterator.hasNext()) {
            collection.add(iterator.next());
        }
    }

    /**
     * Adds all elements in the enumeration to the given collection.
     *
     * @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
     */
    public static void addAll(Collection collection, Enumeration enumeration) {
        while (enumeration.hasMoreElements()) {
            collection.add(enumeration.nextElement());
        }
    }

    /**
     * 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
     */
    public static void addAll(Collection collection, Object[] elements) {
        for (int i = 0, size = elements.length; i < size; i++) {
            collection.add(elements[i]);
        }
    }
}

Related

  1. add(Collection collection, T object)
  2. add_all(Collection target, Collection source)
  3. add_news(Collection target, Collection to_add)
  4. addAll(C collection, Iterable add)
  5. addAll(C collection, T... elements)
  6. addAll(Collection collection, Object[] array)
  7. addAll(Collection collection, Object[] array)
  8. addAll(Collection ret, Object[] elements)
  9. addAll(Collection source, Collection target)