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

CollectioncopyStringCollection(Collection strings)
copy String Collection
if (strings == null) {
    return null;
Collection<String> result = new ArrayList<String>(strings.size());
result.addAll(strings);
return result;
ArrayListcopyWithoutNull(Collection orig)
copy Without Null
ArrayList<E> ret = new ArrayList<E>();
if (orig == null)
    return ret;
for (E e : orig) {
    if (e != null)
        ret.add(e);
return ret;
...
SetcreateSet(Collection toCopy)
create Set
return new HashSet(toCopy);
CollectionmaskedCopyOf(final Collection source, final Collection mask)
masked Copy Of
final Collection<T> copy = new LinkedList<T>(source);
copy.retainAll(new ArrayList<T>(mask));
return copy;
CollectionshallowCopy(Collection collection)
shallow Copy
ArrayList<T> copied = new ArrayList<T>(collection.size());
for (T element : collection) {
    copied.add(element);
return copied;
ListtoUnmodifiableCopy(Collection collection)
to Unmodifiable Copy
return Collections.unmodifiableList(new ArrayList<T>(collection));