Here you can find the source of clone(final List
Parameter | Description |
---|---|
list | the list to clone |
E | parametrized list type |
public static <E> List<E> clone(final List<E> list)
//package com.java2s; /*//from w ww . j av a2 s. c om * Wegas * http://wegas.albasim.ch * * Copyright (c) 2013, 2014, 2015 School of Business and Engineering Vaud, Comem * Licensed under the MIT License */ import java.util.*; public class Main { /** * Clone a list, not its content * * @param list the list to clone * @param <E> parametrized list type * @return a new list with the same content as the original list */ public static <E> List<E> clone(final List<E> list) { List<E> newInstance; try { newInstance = list.getClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { //fallback to ArrayList newInstance = new ArrayList<>(); } newInstance.addAll(list); return newInstance; } }