Java List Copy copy(List toCopy)

Here you can find the source of copy(List toCopy)

Description

Copies the given list.

License

Open Source License

Parameter

Parameter Description
toCopy the list to be copied
T the type of the instances the list is holding

Return

the copied list

Declaration

public static <T> List<T> copy(List<T> toCopy) 

Method Source Code

//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;
    }
}

Related

  1. copy(List list)
  2. copy(List list)
  3. copy(List list)
  4. copy(List original)
  5. copy(List toCopy)
  6. copy(List[] sourceLists, List[] destLists)
  7. copyAndClearList(List sourceList)
  8. copyAndRemove(final List in, final String remove)
  9. copyAndSet(final Map> in, final String key, final String value)