Java List Clone clone(List input)

Here you can find the source of clone(List input)

Description

clone

License

Open Source License

Declaration

public static <T> List<T> clone(List<T> input) 

Method Source Code


//package com.java2s;
/* This file is part of LiveCG.
 *
 * Copyright (C) 2013  Sebastian Kuerten
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version./*from  ww  w.  j a  va  2s .  c  o m*/
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static <T> List<T> clone(List<T> input) {
        if (input == null) {
            return null;
        }
        List<T> copy = new ArrayList<T>();
        for (T object : input) {
            copy.add(object);
        }
        return copy;
    }

    public static <K, V> Map<K, V> clone(Map<K, V> input) {
        if (input == null) {
            return null;
        }
        Map<K, V> copy = new HashMap<K, V>();
        for (Entry<K, V> entry : input.entrySet()) {
            copy.put(entry.getKey(), entry.getValue());
        }
        return copy;
    }
}

Related

  1. clone(final List list)
  2. clone(List in)
  3. clone(List> doc)
  4. clone(List list)
  5. clone(List list)
  6. cloneAdd(final List list, final E... element)
  7. CloneList(final Collection list)
  8. cloneList(final List l, final int n)
  9. cloneList(List aList)

  10. HOME | Copyright © www.java2s.com 2016