Java List Copy copyList(final List list)

Here you can find the source of copyList(final List list)

Description

Return a simple "copy" of the list of objects without cloning each object instance

License

Open Source License

Parameter

Parameter Description
K any type
list list of objects to clone

Return

deep "copy" of the list

Declaration

@SuppressWarnings("unchecked")
public static <K> List<K> copyList(final List<K> list) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*  ww w .  j a v a2s.com*/
     * Return a simple "copy" of the list of objects without cloning each object instance
     * 
     * @param <K> any type
     * @param list list of objects to clone
     * @return deep "copy" of the list
     */
    @SuppressWarnings("unchecked")
    public static <K> List<K> copyList(final List<K> list) {
        if (list != null) {
            final List<K> newList = new ArrayList<K>(list.size());
            for (K o : list) {
                newList.add(o);
            }
            return newList;
        }
        return null;
    }
}

Related

  1. copyIntArray(List li)
  2. copyInto(List source, List dest)
  3. copyList(Collection c)
  4. copyList(Collection list)
  5. copyList(final List source, final List destination)
  6. copyList(List objects)
  7. copyList(List source, List destination)
  8. copyList(List src)
  9. copyList(List list)