Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Enumeration; import java.util.Iterator; public class Main { /** * Adds all elements in the iteration to the given collection. * * @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 <E> void addAll(Collection<E> collection, Iterator<E> iterator) { if (collection == null || iterator == null) { return; } while (iterator.hasNext()) { collection.add(iterator.next()); } } /** * Adds all elements in the enumeration to the given collection. * * @param collection * the collection to add to, must not be null * @param enumeration * the enumeration of elements to add, must not be null * @throws NullPointerException * if the collection or enumeration is null */ public static <E> void addAll(Collection<E> collection, Enumeration<E> enumeration) { if (collection == null || enumeration == null) { return; } while (enumeration.hasMoreElements()) { collection.add(enumeration.nextElement()); } } /** * Adds all elements in the array to the given collection. * * @param collection * the collection to add to, must not be null * @param elements * the array of elements to add, must not be null * @throws NullPointerException * if the collection or array is null */ public static <E> void addAll(Collection<E> collection, E[] elements) { if (collection == null || elements == null) { return; } for (E e : elements) { collection.add(e); } } }