Java Utililty Methods Collection Copy

List of utility methods to do Collection Copy

Description

The list of methods to do Collection Copy are organized into topic(s).

Method

Listcopy(Collection args)
Make a copy of the parameter.
List<E> dest = new ArrayList<E>(args.size());
dest.addAll(args);
return dest;
Listcopy(Collection collection)
copy
@SuppressWarnings("unchecked")
List<T> ret = (List<T>) provideListFor(Object.class);
ret.addAll(collection);
return ret;
Listcopy(final Collection in)
copy
return unmodifiableList(new ArrayList<String>(in));
ArrayListcopy(final Collection collection)
Returns copy of the specified list.
if (collection == null) {
    return null;
return new ArrayList<T>(collection);
ArrayListcopy(final Collection collection)
Returns copy of the specified list.
if (collection == null) {
    return null;
return new ArrayList<T>(collection);
Collectioncopy2Collection(Object[] strs)
copy Collection
Collection result = null;
if (strs == null) {
    result = new ArrayList(0);
} else {
    result = new ArrayList(strs.length);
    for (int i = 0; i < strs.length; i++) {
        result.add(strs[i]);
return result;
voidcopyColl(Collection out, Iterable set)
copy Coll
Iterator<?> it = set.iterator();
while (it.hasNext()) {
    ((Collection<Object>) out).add(it.next());
voidcopyIntoCollectionFrom(Collection collection, Iterable iterable)
Copies all elements from the given Iterable into the given Collection
if (collection != null && iterable != null) {
    for (E element : iterable) {
        collection.add(element);
voidcopyNSorted(final Collection source, final Collection dest, final Comparator order, final int n)
Sorts source and adds the first n entries to dest.
final List<? extends T> src = Collections.list(Collections.enumeration(source));
Collections.sort(src, order);
final Iterator<? extends T> it = src.iterator();
final int maxEntries = dest.size() + n;
while (it.hasNext() && dest.size() < maxEntries) {
    dest.add(it.next());
voidcopyRemainder(final T[] sourceArray, final int startIndex, final Collection collector)
Adds all elements of the given array to the collector, starting from the given index.
for (int index = startIndex; index < sourceArray.length; index++) {
    collector.add(sourceArray[index]);