Java Utililty Methods List Copy

List of utility methods to do List Copy

Description

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

Method

ListcopyFirst(List list, int count)
Copies count items off of list, starting from the beginning.
List<T> ret = new ArrayList<T>(list.size() < count ? list.size() : count);
int i = 0;
for (T elem : list) {
    ret.add(elem);
    if (i++ > count) {
        break;
return ret;
ListcopyIntArray(List li)
copy Int Array
List<int[]> liC = new ArrayList<int[]>(li.size());
for (int[] a : li) {
    int[] c = new int[a.length];
    System.arraycopy(a, 0, c, 0, a.length);
    liC.add(c);
return liC;
voidcopyInto(List source, List dest)
copy Into
dest.clear();
for (T obj : source)
    dest.add(obj);
ListcopyList(Collection c)
copy List
if (c == null || c.size() == 0) {
    return new ArrayList<T>(0);
} else {
    return new ArrayList<T>(c);
ListcopyList(Collection list)
copy List
List<T> result = new ArrayList<>();
for (T el : list)
    result.add(el);
return result;
voidcopyList(final List source, final List destination)
Copy the contents of the source list to the destination list Any items in the destination list before the copy will be removed
if (source != null && destination != null) {
    destination.clear();
    for (Object obj : source) {
        destination.add(obj);
ListcopyList(final List list)
Return a simple "copy" of the list of objects without cloning each object instance
if (list != null) {
    final List<K> newList = new ArrayList<K>(list.size());
    for (K o : list) {
        newList.add(o);
    return newList;
return null;
...
ListcopyList(List objects)
Copies a List into a new List.
if (objects == null) {
    return null;
List newList = new ArrayList(objects.size());
for (Object o : objects) {
    newList.add(o);
return newList;
...
voidcopyList(List source, List destination)
copy List
destination.clear();
for (Object o : source) {
    destination.add(o);
ListcopyList(List src)
Copy specified list to a new list
List lstResult = new ArrayList();
if (src != null) {
    for (Iterator it = src.iterator(); it.hasNext();) {
        lstResult.add(it.next());
return lstResult;