Android examples for java.util:Iterable
Add all items in iterator to target collection
/*/*from w w w . j a va 2s .c o m*/ ******************************************************************************* * Copyright (C) 1996-2015, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.regex.Matcher; import android.icu.text.UTF16; import android.icu.text.UnicodeSet; import android.icu.text.UnicodeSetIterator; public class Main{ /** * Add all items in iterator to target collection * @param <T> * @param <U> * @param source * @param target * @return */ public static <T, U extends Collection<T>> U addAll(Iterator<T> source, U target) { while (source.hasNext()) { target.add(source.next()); } return target; // for chaining } }