Here you can find the source of copy(List
Parameter | Description |
---|---|
toCopy | the list to be copied |
T | the type of the instances the list is holding |
public static <T> List<T> copy(List<T> toCopy)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012-2013 EclipseSource Muenchen GmbH and others. * //w ww . j a v a 2 s. c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Otto von Wesendonk, Edgar Mueller - initial API and implementation ******************************************************************************/ import java.util.ArrayList; import java.util.List; public class Main { /** * Copies the given list. * * @param toCopy * the list to be copied * @return the copied list * * @param <T> the type of the instances the list is holding */ public static <T> List<T> copy(List<T> toCopy) { if (toCopy == null) { return null; } final ArrayList<T> result = new ArrayList<T>(toCopy.size()); for (final T element : toCopy) { result.add(element); } return result; } }