Here you can find the source of copyList(final List
Parameter | Description |
---|---|
K | any type |
list | list of objects to clone |
@SuppressWarnings("unchecked") public static <K> List<K> copyList(final List<K> list)
//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; } }