Here you can find the source of addAll(final C collection, final Iterator
Parameter | Description |
---|---|
T | a parameter |
C | a parameter |
collection | a parameter |
iter | a parameter |
public static <T, C extends Collection<T>> C addAll(final C collection, final Iterator<T> iter)
//package com.java2s; /**//from w w w .j av a 2s . c o m * Copyright 2010 Molindo GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Collection; import java.util.Iterator; public class Main { /** * adds all elements from iter to collection * * @param <T> * @param <C> * @param collection * @param iter * @return */ public static <T, C extends Collection<T>> C addAll(final C collection, final Iterator<T> iter) { while (iter.hasNext()) { collection.add(iter.next()); } return collection; } /** * * @param <T> * @param iter * @return the next element if available, <code>null</code> otherwise */ public static <T> T next(final Iterator<T> iter) { return iter == null || !iter.hasNext() ? null : iter.next(); } }