1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-10-31 17:45:58 +01:00

Add CollectionUtils.addAll(iterator, collection)

This commit is contained in:
Paul Schaub 2022-05-17 18:15:54 +02:00
parent 51baa0e5cb
commit 77d010ec94

View file

@ -6,6 +6,7 @@ package org.pgpainless.util;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@ -60,4 +61,17 @@ public final class CollectionUtils {
}
return false;
}
/**
* Add all items from the iterator to the collection.
*
* @param <T> type of item
* @param iterator iterator to gather items from
* @param collection collection to add items to
*/
public static <T> void addAll(Iterator<T> iterator, Collection<T> collection) {
while (iterator.hasNext()) {
collection.add(iterator.next());
}
}
}